Add rule processors for country and state (https://github.com/woocommerce/woocommerce-admin/pull/5203)
Co-authored-by: Rebecca Scott <me@becdetat.com>
This commit is contained in:
parent
ad8f8c5b08
commit
27a6b4d967
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue