Published on

Woocommerce Update product quantity after successful order

Authors

Time like this, below hook, can be used.

functions.php
// 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');	
    }
  }
});