wc_restock_refunded_items

Restock items during refund.

Description

wc_restock_refunded_items( (WC_Order) $order, (array) $refunded_line_items ); 

Parameters (2)

0. $order (WC_Order)
The order.
1. $refunded_line_items (array)
The refunded line items.

Usage

  1. if ( !function_exists( 'wc_restock_refunded_items' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-order-functions.php'; 
  3.  
  4. // The order. 
  5. $order = null; 
  6.  
  7. // The refunded line items. 
  8. $refunded_line_items = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wc_restock_refunded_items($order, $refunded_line_items); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-order-functions.php  
  1. function wc_restock_refunded_items( $order, $refunded_line_items ) { 
  2. $line_items = $order->get_items(); 
  3.  
  4. foreach ( $line_items as $item_id => $item ) { 
  5. if ( ! isset( $refunded_line_items[ $item_id ], $refunded_line_items[ $item_id ]['qty'] ) ) { 
  6. continue; 
  7. $product = $item->get_product(); 
  8.  
  9. if ( $product && $product->managing_stock() ) { 
  10. $old_stock = $product->get_stock_quantity(); 
  11. $new_stock = wc_update_product_stock( $product, $refunded_line_items[ $item_id ]['qty'], 'increase' ); 
  12.  
  13. $order->add_order_note( sprintf( __( 'Item #%1$s stock increased from %2$s to %3$s.', woocommerce ), $product->get_id(), $old_stock, $new_stock ) ); 
  14.  
  15. do_action( 'woocommerce_restock_refunded_item', $product->get_id(), $old_stock, $new_stock, $order, $product );