Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
woocommerce set_manage_stock not work in woocommerce_process_product_meta action

I try to change the stock fileds programmatically , But it fail woth some fileds.

My question is: Why the set_manage_stock in the action not work , the set_stock_status work:

add_action('woocommerce_process_product_meta', function($post_id) {

    $product = wc_get_product($post_id);

    if( $_POST['_myvariable']==='yes'){

    $product->set_manage_stock(false);
    $product->set_stock_status('instock');
    $product->set_stock_quantity(99);

    }
    else{

        $product->set_manage_stock(true);
        $product->set_stock_status('instock');
        $product->set_stock_quantity(10);
    
    }

    $product->save();

}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Tested OK with WooCommerce 6.3. This will create a product automatically when you add a new product from the admin.

/**
 * Save meta box data.
 *
 * @param int     $post_id WP post id.
 * @param WP_Post $post Post object.
 */
function action_woocommerce_process_product_meta($post_id, $post) {
    // make action magic happen here... 


    $product = new WC_Product_Simple();
    $product->set_name('Sample product ');
    $product->set_status('publish');
    $product->set_catalog_visibility('visible');
    $product->set_price(19.99);
    $product->set_regular_price(19.99);
    $product->set_sold_individually(true);
    $product->set_manage_stock(true);
    $product->set_stock_status('instock');
    $product->set_stock_quantity(10);
    $product->save();
}

// add the action 
add_action('woocommerce_process_product_meta', 'action_woocommerce_process_product_meta', 10, 2);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!