Prevent possible PHP warnings produced by 'woocommerce_ajax_order_items_removed' hook (#37178)

* Remove superfluous check.

* Prevent PHP warnings in `woocommerce_ajax_order_items_removed`

* Add changelog
This commit is contained in:
Jorge A. Torres 2023-03-16 08:42:01 -03:00 committed by GitHub
parent 6f757f8991
commit b19ad2f6d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: tweak
Prevent 'woocommerce_ajax_order_items_removed' from generating PHP warnings.

View File

@ -1315,7 +1315,7 @@ class WC_AJAX {
'city' => isset( $_POST['city'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['city'] ) ) ) : '',
);
if ( ! is_array( $order_item_ids ) && is_numeric( $order_item_ids ) ) {
if ( is_numeric( $order_item_ids ) ) {
$order_item_ids = array( $order_item_ids );
}
@ -1332,6 +1332,10 @@ class WC_AJAX {
$item_id = absint( $item_id );
$item = $order->get_item( $item_id );
if ( ! $item ) {
continue;
}
// Before deleting the item, adjust any stock values already reduced.
if ( $item->is_type( 'line_item' ) ) {
$changed_stock = wc_maybe_adjust_line_item_product_stock( $item, 0 );
@ -1363,7 +1367,7 @@ class WC_AJAX {
* @param bool|array|WP_Error $changed_store Result of wc_maybe_adjust_line_item_product_stock().
* @param bool|WC_Order|WC_Order_Refund $order As returned by wc_get_order().
*/
do_action( 'woocommerce_ajax_order_items_removed', $item_id, $item, $changed_stock, $order );
do_action( 'woocommerce_ajax_order_items_removed', $item_id ?? 0, $item ?? false, $changed_stock ?? false, $order );
// Get HTML to return.
ob_start();