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();
}