How to change sold_individually product property in WooCommerce

Swift :

I need to update '_sold_individually' field of product in woocommerce.

I have using below field it isn't working

update_post_meta($product->get_id(), '_sold_individually', "yes");

Any alternate please help thanks!

LoicTheAztec :

As you are already using the WC_Product instance object $product, you can better try using set_sold_individually() dedicated method this way:

$product->set_sold_individually( true );
$product->save();

It should better work and sync product cached data…

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=198900&siteId=1