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 <john@nimblelight.com>
This commit is contained in:
Jorge A. Torres 2023-11-22 15:52:24 +00:00 committed by GitHub
parent 003c3c721e
commit 409a256815
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fix `TypeError` in `WC_Discounts->apply_coupons()` when being called a second time.

View File

@ -7,7 +7,6 @@
*/ */
use Automattic\WooCommerce\Utilities\NumberUtil; use Automattic\WooCommerce\Utilities\NumberUtil;
use Automattic\WooCommerce\Utilities\StringUtil;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
@ -257,7 +256,7 @@ class WC_Discounts {
} }
$coupon_code = $coupon->get_code(); $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 ); $this->discounts[ $coupon_code ] = array_fill_keys( array_keys( $this->items ), 0 );
} }