Co-authored-by: Rebecca Scott <me@becdetat.com>
This commit is contained in:
Bec Scott 2020-09-29 15:21:44 +10:00 committed by GitHub
parent ad8f8c5b08
commit 27a6b4d967
4 changed files with 140 additions and 0 deletions

View File

@ -0,0 +1,55 @@
<?php
/**
* Rule processor that performs a comparison operation against the base
* location - country.
*/
namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications;
defined( 'ABSPATH' ) || exit;
/**
* Rule processor that performs a comparison operation against the base
* location - country.
*/
class BaseLocationCountryRuleProcessor implements RuleProcessorInterface {
/**
* Performs a comparison operation against the base location - country.
*
* @param object $rule The specific rule being processed by this rule processor.
* @param object $stored_state Stored state.
*
* @return bool The result of the operation.
*/
public function process( $rule, $stored_state ) {
$base_location = wc_get_base_location();
if ( ! $base_location ) {
return false;
}
return ComparisonOperation::compare(
$base_location['country'],
$rule->value,
$rule->operation
);
}
/**
* Validates the rule.
*
* @param object $rule The rule to validate.
*
* @return bool Pass/fail.
*/
public function validate( $rule ) {
if ( ! isset( $rule->value ) ) {
return false;
}
if ( ! isset( $rule->operation ) ) {
return false;
}
return true;
}
}

View File

@ -0,0 +1,55 @@
<?php
/**
* Rule processor that performs a comparison operation against the base
* location - state.
*/
namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications;
defined( 'ABSPATH' ) || exit;
/**
* Rule processor that performs a comparison operation against the base
* location - state.
*/
class BaseLocationStateRuleProcessor implements RuleProcessorInterface {
/**
* Performs a comparison operation against the base location - state.
*
* @param object $rule The specific rule being processed by this rule processor.
* @param object $stored_state Stored state.
*
* @return bool The result of the operation.
*/
public function process( $rule, $stored_state ) {
$base_location = wc_get_base_location();
if ( ! $base_location ) {
return false;
}
return ComparisonOperation::compare(
$base_location['state'],
$rule->value,
$rule->operation
);
}
/**
* Validates the rule.
*
* @param object $rule The rule to validate.
*
* @return bool Pass/fail.
*/
public function validate( $rule ) {
if ( ! isset( $rule->value ) ) {
return false;
}
if ( ! isset( $rule->operation ) ) {
return false;
}
return true;
}
}

View File

@ -48,6 +48,10 @@ class GetRuleProcessor {
return new OnboardingProfileRuleProcessor();
case 'is_ecommerce':
return new IsEcommerceRuleProcessor();
case 'base_location_country':
return new BaseLocationCountryRuleProcessor();
case 'base_location_state':
return new BaseLocationStateRuleProcessor();
}
return new FailRuleProcessor();

View File

@ -342,4 +342,30 @@ This passes when the store is on a WordPress.com site with the eCommerce plan.
`value` is required.
### Base location - country
This passes when the store is located in the specified country.
```
{
"type": "base_location_country",
"value": "US",
"operation": "="
}
```
`value` and `operation` are both required.
### Base location - state
This passes when the store is located in the specified state.
```
{
"type": "base_location_state",
"value": "TX",
"operation": "="
}
```
`value` and `operation` are both required.