0

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 1

0

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
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.