Fix base location remote inbox rule (#38794)

* Add another check in base location rule to fix OBW extensions bug

* Changelog

* Lint

* Add isset check

* Fix logic

* Lint
This commit is contained in:
Ilyas Foo 2023-06-19 19:50:52 +08:00 committed by GitHub
parent baa0a275e3
commit dbd8d1be12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Add another check in base location rule to fix OBW extensions bug

View File

@ -29,8 +29,12 @@ class BaseLocationCountryRuleProcessor implements RuleProcessorInterface {
return false;
}
$onboarding_profile = get_option( 'woocommerce_onboarding_profile', array() );
$is_address_default = 'US' === $base_location['country'] && 'CA' === $base_location['state'] && empty( get_option( 'woocommerce_store_address', '' ) );
$is_store_country_set = isset( $onboarding_profile['is_store_country_set'] ) && $onboarding_profile['is_store_country_set'];
// Return false if the location is the default country and if onboarding hasn't been finished or the store address not been updated.
if ( 'US' === $base_location['country'] && 'CA' === $base_location['state'] && empty( get_option( 'woocommerce_store_address', '' ) ) && OnboardingProfile::needs_completion() ) {
if ( $is_address_default && OnboardingProfile::needs_completion() && ! $is_store_country_set ) {
return false;
}

View File

@ -116,6 +116,22 @@ class WC_Admin_Tests_RemoteInboxNotifications_BaseLocationCountryRuleProcessor e
$this->assertEquals( true, $result );
}
/**
* Tests that the processor returns true if profiler option's `is_store_country_set` is true.
*
* @group fast
*/
public function test_spec_succeeds_if_base_location_is_default_and_is_store_country_set_is_true() {
update_option( 'woocommerce_default_country', 'US:CA' );
update_option( OnboardingProfile::DATA_OPTION, array( 'is_store_country_set' => true ) );
$processor = new BaseLocationCountryRuleProcessor();
$result = $processor->process( $this->get_rule(), new stdClass() );
$this->assertEquals( true, $result );
}
/**
* Tests that the processor returns true if country is default but address is updated.
*