Skip to content

Allow ECE display when default customer location is set to geolocate #4417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*** Changelog ***

= 9.6.0 - xxxx-xx-xx =
* Tweak - Allow the display of express payment methods when default customer location is set to "Geolocate" or "Geolocate (with page caching support)".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two concerns:

  • I think this should be flagged as an Update, not a Tweak
  • We should remove the trailing .
Suggested change
* Tweak - Allow the display of express payment methods when default customer location is set to "Geolocate" or "Geolocate (with page caching support)".
* Update - Allow the display of express checkout when default customer location is set to "Geolocate" or "Geolocate (with page caching support)"

* Add - Adds a new promotional banner to promote the BNPL payment methods (Klarna, Afterpay, and Affirm) on the settings page.
* Fix - Adds an exception to be thrown when the order item quantity is zero, during the retrieval of level 3 data from an order.
* Dev - Deprecates the WC_Stripe_Order class and removes its inclusion call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,11 +719,14 @@ private function should_hide_ece_based_on_tax_setup() {
return false;
}

$is_taxable = $this->is_product_or_cart_taxable();
$needs_shipping = $this->product_or_cart_needs_shipping();
$is_tax_based_on_billing = 'billing' === get_option( 'woocommerce_tax_based_on' );

if ( $is_taxable && $is_tax_based_on_billing && ! $needs_shipping ) {
$is_taxable = $this->is_product_or_cart_taxable();
$needs_shipping = $this->product_or_cart_needs_shipping();
$is_tax_based_on_billing = 'billing' === get_option( 'woocommerce_tax_based_on' );
$default_customer_address = get_option( 'woocommerce_default_customer_address' );

if ( $is_taxable && $is_tax_based_on_billing && ! $needs_shipping
// Allow ECE to be displayed if the default customer address is set to `geolocation` or `geolocation_ajax`.
&& ! in_array( $default_customer_address, [ 'geolocation', 'geolocation_ajax' ], true ) ) {
return true;
}
Comment on lines +727 to 731
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a filter here rather than just defaulting on.


Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o

= 9.6.0 - xxxx-xx-xx =

* Tweak - Allow the display of express payment methods when default customer location is set to "Geolocate" or "Geolocate (with page caching support)".
* Add - Adds a new promotional banner to promote the BNPL payment methods (Klarna, Afterpay, and Affirm) on the settings page.
* Fix - Adds an exception to be thrown when the order item quantity is zero, during the retrieval of level 3 data from an order.
* Dev - Deprecates the WC_Stripe_Order class and removes its inclusion call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,23 @@ public function set_up_shipping_methods() {
/**
* Test should_show_express_checkout_button, tax logic.
*
* @param array $cart_contents Cart contents.
* @param bool $is_pay_for_order Whether the current request is for a "Pay for Order" page.
* @param string $tax_based_on Tax based on setting.
* @param mixed $filter_value Value for the filter `wc_stripe_should_hide_express_checkout_button_based_on_tax_setup`.
* @param mixed $default_customer_address Default customer address.
* @return void
*
* @dataProvider provide_test_hides_ece_if_cannot_compute_taxes
*/
public function test_hides_ece_if_cannot_compute_taxes( $cart_contents, $is_pay_for_order, $tax_based_on, $filter_value, $expected ) {
public function test_hides_ece_if_cannot_compute_taxes(
$cart_contents,
$is_pay_for_order,
$tax_based_on,
$filter_value,
$default_customer_address,
$expected
) {
$this->set_up_shipping_methods();
$this->create_products_for_test_hides_ece_if_cannot_compute_taxes();

Expand Down Expand Up @@ -114,6 +128,10 @@ function () use ( $filter_value ) {
update_option( 'woocommerce_calc_taxes', 'yes' ); // Should be overriden by product tax status.
update_option( 'woocommerce_tax_based_on', $tax_based_on );

if ( ! is_null( $default_customer_address ) ) {
update_option( 'woocommerce_default_customer_address', $default_customer_address );
}

WC()->session->init();
WC()->cart->empty_cart();

Expand All @@ -129,6 +147,8 @@ function () use ( $filter_value ) {
WC()->cart->empty_cart();
WC()->session->cleanup_sessions();
WC()->payment_gateways()->payment_gateways = $original_gateways;

update_option( 'woocommerce_default_customer_address', 'base' );
}

/**
Expand Down Expand Up @@ -174,53 +194,68 @@ public function provide_test_hides_ece_if_cannot_compute_taxes() {
$show = true;
return [
'Hide if cart has virtual product and tax is based on billing address.' => [
'cart contents' => [ 'virtual_taxable', 'virtual_nontaxable' ],
'is pay for order' => false,
'tax based on' => 'billing',
'filter value' => null,
'expected' => $hide,
'cart contents' => [ 'virtual_taxable', 'virtual_nontaxable' ],
'is pay for order' => false,
'tax based on' => 'billing',
'filter value' => null,
'default customer address' => null,
'expected' => $hide,
],
'Do not hide if cart has virtual product and tax is based on billing address, but default customer location is set to geolocation.' => [
'cart contents' => [ 'virtual_taxable', 'virtual_nontaxable' ],
'is pay for order' => false,
'tax based on' => 'billing',
'filter value' => null,
'default customer address' => 'geolocation',
'expected' => $show,
],
'Do not hide if cart has virtual product and tax is based on billing address, but filter forces to show.' => [
'cart contents' => [ 'virtual_taxable', 'virtual_nontaxable' ],
'is pay for order' => false,
'tax based on' => 'billing',
'filter value' => false,
'expected' => $show,
'cart contents' => [ 'virtual_taxable', 'virtual_nontaxable' ],
'is pay for order' => false,
'tax based on' => 'billing',
'filter value' => false,
'default customer address' => null,
'expected' => $show,
],
'Do not hide if Pay for Order page.' => [
'cart contents' => [ 'virtual_taxable' ],
'is pay for order' => true,
'tax based on' => 'billing',
'filter value' => null,
'expected' => $show,
'cart contents' => [ 'virtual_taxable' ],
'is pay for order' => true,
'tax based on' => 'billing',
'filter value' => null,
'default customer address' => null,
'expected' => $show,
],
'Do not hide if taxes are not enabled.' => [
'cart contents' => [ 'virtual_nontaxable' ],
'is pay for order' => false,
'tax based on' => 'billing',
'filter value' => null,
'expected' => $show,
'cart contents' => [ 'virtual_nontaxable' ],
'is pay for order' => false,
'tax based on' => 'billing',
'filter value' => null,
'default customer address' => null,
'expected' => $show,
],
'Do not hide if cart has virtual product and tax is based on shipping address.' => [
'cart contents' => [ 'virtual_taxable', 'virtual_nontaxable' ],
'is pay for order' => false,
'tax based on' => 'shipping',
'filter value' => null,
'expected' => $show,
'cart contents' => [ 'virtual_taxable', 'virtual_nontaxable' ],
'is pay for order' => false,
'tax based on' => 'shipping',
'filter value' => null,
'default customer address' => null,
'expected' => $show,
],
'Do not hide if taxes are not based on customer billing or shipping address.' => [
'cart contents' => [ 'virtual_taxable' ],
'is pay for order' => false,
'tax based on' => 'base',
'filter value' => null,
'expected' => $show,
'cart contents' => [ 'virtual_taxable' ],
'is pay for order' => false,
'tax based on' => 'base',
'filter value' => null,
'default customer address' => null,
'expected' => $show,
],
'Do not hide if cart requires shipping.' => [
'cart contents' => [ 'shippable_taxable' ],
'is pay for order' => false,
'tax based on' => 'billing',
'filter value' => null,
'expected' => $show,
'cart contents' => [ 'shippable_taxable' ],
'is pay for order' => false,
'tax based on' => 'billing',
'filter value' => null,
'default customer address' => null,
'expected' => $show,
],
];
}
Expand Down
Loading