Resolved fatal error when applying Brands-restricted coupon (#51577)

* Resolved fatal error when applying Brands-restricted coupon

* Add changefile(s) from automation for the following project(s): woocommerce

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Jason Kytros 2024-09-24 14:16:03 +03:00 committed by GitHub
parent 4858ae62aa
commit 85a048f1fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Resolved fatal error when applying Brands-restricted coupon

View File

@ -69,17 +69,17 @@ class WC_Brands_Coupons {
// 1) Coupon has a brand requirement but no products in the cart have the brand.
if ( ! $included_brands_match && ! empty( $brand_coupon_settings['included_brands'] ) ) {
throw new Exception( WC_Coupon::E_WC_COUPON_NOT_APPLICABLE ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
throw new Exception( $coupon->get_coupon_error( WC_Coupon::E_WC_COUPON_NOT_APPLICABLE ), WC_Coupon::E_WC_COUPON_NOT_APPLICABLE ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
}
// 2) All products in the cart match brand exclusion rule.
if ( count( $items ) === $excluded_brands_matches ) {
throw new Exception( self::E_WC_COUPON_EXCLUDED_BRANDS ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
throw new Exception( __( 'Sorry, this coupon is not applicable to the brands of selected products.', 'woocommerce' ), self::E_WC_COUPON_EXCLUDED_BRANDS ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
}
// 3) For a cart discount, there is at least one product in cart that matches exclusion rule.
if ( $coupon->is_type( 'fixed_cart' ) && $excluded_brands_matches > 0 ) {
throw new Exception( self::E_WC_COUPON_EXCLUDED_BRANDS ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
throw new Exception( __( 'Sorry, this coupon is not applicable to the brands of selected products.', 'woocommerce' ), self::E_WC_COUPON_EXCLUDED_BRANDS ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
}
return $valid;