Fire action if order line item has been restored (#40848)
* Fire action if order line item has been restored This is the equivalent to the 'woocommerce_reduce_order_item_stock' hook in the wc_reduce_stock_levels() function. * Add @since tag to docblock * Change position of @since tag * Add changelog * Use tabs for indents * Fix indents again * Fix another indent
This commit is contained in:
parent
bb9b332ae2
commit
4df98f6379
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: add
|
||||||
|
|
||||||
|
Added 'woocommerce_restore_order_item_stock' filter for restored line item stock on canceled orders
|
|
@ -296,6 +296,7 @@ function wc_increase_stock_levels( $order_id ) {
|
||||||
|
|
||||||
$item_name = $product->get_formatted_name();
|
$item_name = $product->get_formatted_name();
|
||||||
$new_stock = wc_update_product_stock( $product, $item_stock_reduced, 'increase' );
|
$new_stock = wc_update_product_stock( $product, $item_stock_reduced, 'increase' );
|
||||||
|
$old_stock = $new_stock - $item_stock_reduced;
|
||||||
|
|
||||||
if ( is_wp_error( $new_stock ) ) {
|
if ( is_wp_error( $new_stock ) ) {
|
||||||
/* translators: %s item name. */
|
/* translators: %s item name. */
|
||||||
|
@ -306,7 +307,18 @@ function wc_increase_stock_levels( $order_id ) {
|
||||||
$item->delete_meta_data( '_reduced_stock' );
|
$item->delete_meta_data( '_reduced_stock' );
|
||||||
$item->save();
|
$item->save();
|
||||||
|
|
||||||
$changes[] = $item_name . ' ' . ( $new_stock - $item_stock_reduced ) . '→' . $new_stock;
|
$changes[] = $item_name . ' ' . $old_stock . '→' . $new_stock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fires when stock restored to a specific line item
|
||||||
|
*
|
||||||
|
* @since 9.1.0
|
||||||
|
* @param WC_Order_Item_Product $item Order item data.
|
||||||
|
* @param int $new_stock New stock.
|
||||||
|
* @param int $old_stock Old stock.
|
||||||
|
* @param WC_Order $order Order data.
|
||||||
|
*/
|
||||||
|
do_action( 'woocommerce_restore_order_item_stock', $item, $new_stock, $old_stock, $order );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $changes ) {
|
if ( $changes ) {
|
||||||
|
|
Loading…
Reference in New Issue