Ad

How To Change Sold_individually Product Property In WooCommerce

- 1 answer

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!

Ad

Answer

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…

Ad
source: stackoverflow.com
Ad