If we need to modify product quantity after successful order in Woo-Commerce then we can use below hook. When we don’t need to decrease product quantity which same then main product but product price is 0.

Time like this, below hook, can be used.

// define the woocommerce_reduce_order_stock callback 
function action_woocommerce_reduce_order_stock( $array ) { 
    // do your logic
}; 
         
// add the action 
add_action( 'woocommerce_reduce_order_stock', 'action_woocommerce_reduce_order_stock', 10, 1 );
/inc/translation-editor/class-wcml-synchronize-product-data.php
add_action( 'woocommerce_reduce_order_stock', array( $this, 'sync_product_stocks_reduce' ) );

Example:

add_action( 'woocommerce_reduce_order_stock', function($order){
  foreach ($order->get_items() as $item_key => $item ){
    if($item->get_subtotal() == 0&& $item->get_total() == 0){
      wc_update_product_stock($item->get_product_id(), $item->get_quantity(), 'increase');	
    }
  }
});

 

0 0 vote
Article Rating
Subscribe
Notify of
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
SEO Referral Program
4 months ago

Awesome post! Keep up the great work! ­čÖé

Sign Up for Our Newsletters

Get notified of the best deals on our WordPress themes.