In WooCommerce, if an item is sold out, I would like to add a category "sold out" to it, so that I can show these items in a separate section.
I created the "sold out" category in the WooCommerce/WordPress Admin panel.
This is what I have in my functions.php:
add_action( 'woocommerce_before_shop_loop_item_title', 'mytheme_display_sold_out_loop_woocommerce' );
function mytheme_display_sold_out_loop_woocommerce() {
global $product;
if ( !$product->is_in_stock() ) {
// add category "sold out"
}
}
Now, how can I automatically add the category "sold out" to any sold out WooCommcerce product?