From 45963144feeef876dc4b4dd16dbe6a0d738abf5c Mon Sep 17 00:00:00 2001 From: Anne Mirasol Date: Wed, 30 Oct 2024 15:51:11 -0500 Subject: [PATCH] Check if taxes are enabled in ECE tax compatibility logic (#3563) * Check if taxes are enabled in ECE tax compatibility logic * Update unit tests --- changelog.txt | 1 + ...lass-wc-stripe-express-checkout-helper.php | 1 + readme.txt | 1 + ...test-wc-stripe-express-checkout-helper.php | 19 +++++++++++++++++++ 4 files changed, 22 insertions(+) diff --git a/changelog.txt b/changelog.txt index 26f98a100..f34a11a2b 100644 --- a/changelog.txt +++ b/changelog.txt @@ -3,6 +3,7 @@ = 8.9.0 - xxxx-xx-xx = * Tweak - Makes the new Stripe Express Checkout Element enabled by default. * Dev - Add multiple unit tests for the Stripe Express Checkout Element implementation (for both frontend and backend). +* Fix - Check if taxes are enabled when applying ECE tax compatibility check. * Fix - Fix ECE error when initial address on load is not defined as a shipping zone. * Fix - Corrected card brand capitalization on the My Account → Subscription page. * Fix - Displays a specific message when an authentication error occurs during checkout for 3DS cards (shortcode version). diff --git a/includes/payment-methods/class-wc-stripe-express-checkout-helper.php b/includes/payment-methods/class-wc-stripe-express-checkout-helper.php index 80d0c1db8..e178c6da3 100644 --- a/includes/payment-methods/class-wc-stripe-express-checkout-helper.php +++ b/includes/payment-methods/class-wc-stripe-express-checkout-helper.php @@ -585,6 +585,7 @@ public function should_show_express_checkout_button() { ( is_product() && ! $this->product_needs_shipping( $this->get_product() ) ) || ( ( is_cart() || is_checkout() ) && ! WC()->cart->needs_shipping() ) ) && + wc_tax_enabled() && in_array( get_option( 'woocommerce_tax_based_on' ), [ 'billing', 'shipping' ], true ) ) { return false; diff --git a/readme.txt b/readme.txt index 82b481063..45a5595e2 100644 --- a/readme.txt +++ b/readme.txt @@ -113,6 +113,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o = 8.9.0 - xxxx-xx-xx = * Tweak - Makes the new Stripe Express Checkout Element enabled by default. * Dev - Add multiple unit tests for the Stripe Express Checkout Element implementation (for both frontend and backend). +* Fix - Check if taxes are enabled when applying ECE tax compatibility check. * Fix - Fix ECE error when initial address on load is not defined as a shipping zone. * Fix - Corrected card brand capitalization on the My Account → Subscription page. * Fix - Displays a specific message when an authentication error occurs during checkout for 3DS cards (shortcode version). diff --git a/tests/phpunit/test-wc-stripe-express-checkout-helper.php b/tests/phpunit/test-wc-stripe-express-checkout-helper.php index d5ad05a8b..a416a4b25 100644 --- a/tests/phpunit/test-wc-stripe-express-checkout-helper.php +++ b/tests/phpunit/test-wc-stripe-express-checkout-helper.php @@ -19,6 +19,18 @@ public function set_up() { $stripe_settings['test_publishable_key'] = 'pk_test_key'; $stripe_settings['test_secret_key'] = 'sk_test_key'; WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings ); + + // Add a shipping zone. + $zone = new WC_Shipping_Zone(); + $zone->set_zone_name( 'Worldwide' ); + $zone->set_zone_order( 1 ); + $zone->save(); + + $flat_rate_id = $zone->add_shipping_method( 'flat_rate' ); + $method = WC_Shipping_Zones::get_shipping_method( $flat_rate_id ); + $option_key = $method->get_instance_option_key(); + $options['cost'] = '5'; + update_option( $option_key, $options ); } /** @@ -52,17 +64,24 @@ public function test_hides_ece_if_cannot_compute_taxes() { WC()->cart->add_to_cart( $virtual_product->get_id(), 1 ); // Hide if cart has virtual product and tax is based on shipping or billing address. + update_option( 'woocommerce_calc_taxes', 'yes' ); update_option( 'woocommerce_tax_based_on', 'billing' ); $this->assertFalse( $wc_stripe_ece_helper_mock->should_show_express_checkout_button() ); update_option( 'woocommerce_tax_based_on', 'shipping' ); $this->assertFalse( $wc_stripe_ece_helper_mock->should_show_express_checkout_button() ); + // Do not hide if taxes are not enabled. + update_option( 'woocommerce_calc_taxes', 'no' ); + $this->assertTrue( $wc_stripe_ece_helper_mock->should_show_express_checkout_button() ); + // Do not hide if taxes are not based on customer billing or shipping address. + update_option( 'woocommerce_calc_taxes', 'yes' ); update_option( 'woocommerce_tax_based_on', 'base' ); $this->assertTrue( $wc_stripe_ece_helper_mock->should_show_express_checkout_button() ); // Do not hide if cart requires shipping. + update_option( 'woocommerce_tax_based_on', 'billing' ); $shippable_product = WC_Helper_Product::create_simple_product(); WC()->cart->add_to_cart( $shippable_product->get_id(), 1 ); $this->assertTrue( $wc_stripe_ece_helper_mock->should_show_express_checkout_button() );