Added woocommerce_reduce_order_item_stock action hook to let other plugin hook functionalities without looping through the order items again and again. (#34721)

* Added woocommerce_reduce_order_item_stock action hook to let other plugins do somthing without looping again the order line items

* changed "product data" to "change details" and updated docblock as instructed

* maintained WP coding standards and change @since docblock tag
This commit is contained in:
Yousuf Hossain 2023-03-09 03:05:40 +06:00 committed by GitHub
parent 83fb31db8e
commit 92f94248cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: enhancement
Added woocommerce_reduce_order_item_stock action hook

View File

@ -197,11 +197,22 @@ function wc_reduce_stock_levels( $order_id ) {
$item->add_meta_data( '_reduced_stock', $qty, true );
$item->save();
$changes[] = array(
$change = array(
'product' => $product,
'from' => $new_stock + $qty,
'to' => $new_stock,
);
$changes[] = $change;
/**
* Fires when stock reduced to a specific line item
*
* @param WC_Order_Item_Product $item Order item data.
* @param array $change Change Details.
* @param WC_Order $order Order data.
* @since 7.6.0
*/
do_action( 'woocommerce_reduce_order_item_stock', $item, $change, $order );
}
wc_trigger_stock_change_notifications( $order, $changes );