Set a variation out of stock in all WooCommerce products

243 Views Asked by At

We have mugs printing system with WooCommerce and we display available printable colors as variations. I need to set out of stock a certain variation in all products, i.e., if we do not have red color availability then I want to set red variation out of stock in all the products.

I didn't find any simple solution for this except setting out of stock the certain variation in all products manually.

Any help is appreciated.

1

There are 1 best solutions below

0
On

$out_of_stock_staus = 'outofstock';

// Updating the stock quantity update_post_meta($product_id, '_stock', 0); update_post_meta( $product_id, '_stock_status', wc_clean( $out_of_stock_staus ) ); wp_set_post_terms( $product_id, 'outofstock', 'product_visibility', true );

I think this meta value you suppose to manage for handling the stock for woocommerce product I don't know regarding hook but this function may help you to figure out