Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

“Sold out” badge on shop pages

Out-of-stock products show a “Sold out” label on their image in the shop and category pages.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Needs WooCommerce
  • Category WooCommerce
  • Tested with WordPress 7.1, WooCommerce 11.1
PHP
<?php

add_action(
	'woocommerce_before_shop_loop_item_title',
	static function () {
		global $product;
		if ( $product instanceof WC_Product && ! $product->is_in_stock() ) {
			echo '<span class="snipfire-soldout">' . esc_html__( 'Sold out', 'woocommerce' ) . '</span>';
		}
	},
	9
);
add_action(
	'wp_head',
	static function () {
		echo '<style>.woocommerce ul.products li.product{position:relative}.snipfire-soldout{position:absolute;top:8px;left:8px;z-index:2;background:#1d2327;color:#fff;font-size:.75rem;font-weight:600;text-transform:uppercase;letter-spacing:.04em;padding:4px 8px;border-radius:3px}</style>';
	}
);

Good to know

For classic shop templates (and the Classic Template block).

In these packs

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.