Website Building » WooCommerce » How Do I Show Sold Out Items in WooCommerce?

How Do I Show Sold Out Items in WooCommerce?

Last updated on January 22, 2023 @ 11:57 am

If you’re using WooCommerce to sell products on your WordPress site, you may want to know how to show sold out items. By default, WooCommerce doesn’t have this functionality, but it’s not difficult to add it.

The first thing you need to do is edit the functions.php file of your child theme. If you don’t have a child theme, you can create one. Then, add the following code:

function WooCommerce_product_ sold_out () {
 global $post;
 $ sold_out = get_post_meta( $post->ID, '_sold_out', true );
   if ( $ sold_out && $ sold_out == 'yes' ) {
     echo 'Sold Out';
   }
}
add_action( 'woocommerce_after_shop_loop _item', 'woocommerce_product _sold out' );

This code will add a “Sold Out” label to any products that have the “Sold Out” meta key set to “Yes”.

PRO TIP: If you are using WooCommerce to sell products on your website, it is important to know how to show sold out items. This will ensure that your customers know which products are no longer available, and help avoid any confusion or frustration.

To show sold out items in WooCommerce, go to the ‘Products’ page in your WordPress admin panel. From here, you will be able to see a list of all the products you have for sale. If any of these products are sold out, they will be marked as ‘Out of stock’.

If you want to hide sold out items from your shop page, you can do so by going to the ‘WooCommerce’ settings page and enabling the ‘Hide out of stock items from the shop page’ option.

Finally, remember to keep your inventory updated so that your customers always have accurate information about what products are available.

If you want to style the “Sold Out” label, you can do so by adding the following CSS to your child theme’s style.css file:

.sold-out { color: #f00; }

You can of course change the color to anything you like. Now when you go to your shop page, any sold out items will have a “Sold Out” label next to them.

Conclusion:

Adding a “Sold Out” label to sold out items in WooCommerce is easy with a few lines of code. This can be useful if you want to make it clear to customers which items are no longer available. You can also style the label with CSS to match your site’s design.

Kathy McFarland

Kathy McFarland

Devops woman in trade, tech explorer and problem navigator.