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

 

1
Leave a Reply

Please Login to comment
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
SEO Referral Program Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
SEO Referral Program
Guest

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

Sign Up for Our Newsletters

Get notified of the best deals on our WordPress themes.