Show a clear "Sold out" badge on out-of-stock products in the shop grid, so shoppers don't click through to find out.
add_action( 'woocommerce_before_shop_loop_item_title', function (): void {
global $product;
if ( $product instanceof WC_Product && ! $product->is_in_stock() ) {
echo '<span class="nahnu-sold-out">Sold out</span>';
}
}, 9 );
add_action( 'wp_head', function (): void {
echo '<style>.woocommerce ul.products li.product{position:relative}.nahnu-sold-out{position:absolute;top:10px;left:10px;z-index:2;padding:4px 10px;border-radius:999px;background:#15131F;color:#fff;font-size:12px;font-weight:700;text-transform:uppercase}</style>';
} );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
If you keep sold-out products visible, shoppers should see their status at a glance. This snippet adds a “Sold out” badge to their image in the shop grid.
The badge is printed on woocommerce_before_shop_loop_item_title at priority 9, just before the product image. It only appears when is_in_stock() is false.
A few lines of CSS position it in the top-left corner of the product card. Adjust the colours to match your brand.
Set a product to Out of stock and open the shop page. Its image should show a “Sold out” badge.