# "Sold Out" Badge on Shop Images

> Adds a "Sold out" label over the image of out-of-stock products in shop and category listings so shoppers can tell at a glance.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, badge, stock, shop
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-sold-out-badge/

## Code

```php
add_action( 'woocommerce_before_shop_loop_item_title', function () {
    global $product;

    if ( ! $product instanceof WC_Product || $product->is_in_stock() ) {
        return;
    }

    echo '<span class="wpide-sold-out" style="position:absolute;top:10px;left:10px;z-index:9;padding:4px 10px;border-radius:3px;background:#1e1e1e;color:#fff;font-size:12px;font-weight:600;text-transform:uppercase;">' . esc_html( 'Sold out' ) . '</span>';
}, 9 );

add_action( 'wp_head', function () {
    echo '<style>.woocommerce ul.products li.product{position:relative;}</style>' . "\n";
} );
```

## Notes

Adjust the colors in the inline style or override the .wpide-sold-out class in your theme CSS.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find ""Sold Out" Badge on Shop Images" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
