From 409a2568153ab9dcf603ecf69dda8fa43a72f747 Mon Sep 17 00:00:00 2001 From: "Jorge A. Torres" Date: Wed, 22 Nov 2023 15:52:24 +0000 Subject: [PATCH] Fix TypeError in WC_Discounts->apply_coupons() when being called a second time [redux] (#41602) * Discounts are not in the format `array( 'string' => 'string' )`, they are in the format `array( 'string' => array( int, int ) );`. * Remove `ArrayUtil` because `ensure_key_is_array` creates the array and returns `true`. * Add Changelog manually * Fix changelog placement. --------- Co-authored-by: John Rom --- plugins/woocommerce/changelog/pr-39234 | 4 ++++ plugins/woocommerce/includes/class-wc-discounts.php | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 plugins/woocommerce/changelog/pr-39234 diff --git a/plugins/woocommerce/changelog/pr-39234 b/plugins/woocommerce/changelog/pr-39234 new file mode 100644 index 00000000000..6425884d84b --- /dev/null +++ b/plugins/woocommerce/changelog/pr-39234 @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Fix `TypeError` in `WC_Discounts->apply_coupons()` when being called a second time. diff --git a/plugins/woocommerce/includes/class-wc-discounts.php b/plugins/woocommerce/includes/class-wc-discounts.php index a202b0cc755..e0c7b7b5ef3 100644 --- a/plugins/woocommerce/includes/class-wc-discounts.php +++ b/plugins/woocommerce/includes/class-wc-discounts.php @@ -7,7 +7,6 @@ */ use Automattic\WooCommerce\Utilities\NumberUtil; -use Automattic\WooCommerce\Utilities\StringUtil; defined( 'ABSPATH' ) || exit; @@ -257,7 +256,7 @@ class WC_Discounts { } $coupon_code = $coupon->get_code(); - if ( StringUtil::is_null_or_whitespace( $this->discounts[ $coupon_code ] ?? null ) ) { + if ( ! isset( $this->discounts[ $coupon_code ] ) || ! is_array( $this->discounts[ $coupon_code ] ) ) { $this->discounts[ $coupon_code ] = array_fill_keys( array_keys( $this->items ), 0 ); }