Skip to content

Commit

Permalink
Check if taxes are enabled in ECE tax compatibility logic (#3563)
Browse files Browse the repository at this point in the history
* Check if taxes are enabled in ECE tax compatibility logic

* Update unit tests
  • Loading branch information
annemirasol authored Oct 30, 2024
1 parent 3db5663 commit 4596314
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
19 changes: 19 additions & 0 deletions tests/phpunit/test-wc-stripe-express-checkout-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down Expand Up @@ -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() );
Expand Down

0 comments on commit 4596314

Please sign in to comment.