How to automatically change the status of product from draft to published when stock qty change from 0 > 1. im trying to hide product that are not available
1 Answer
Does this help?
add_action( 'save_post_product', 'sew_chg_status', 10,2 );
function sew_chg_status( $post_id, $post ){
$product = new WC_Product( $post_id ); //create a WC product with post data
if ( 0 < $_POST['_stock'] ){ // if data sent about stock by WC is strictly superior to 0
$product->set_status( 'publish' ); // change the product status
}
}