Monday, May 9, 2022

[FIXED] How to change sold_individually product property in WooCommerce

Issue

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!


Solution

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…



Answered By - LoicTheAztec
Answer Checked By - David Marino (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.