Introduce Woo Express RIN rule

This commit is contained in:
Manos Psychogyiopoulos 2023-09-29 15:52:09 +03:00
parent 53e53c9a63
commit 85f55d07fc
3 changed files with 91 additions and 0 deletions

View File

@ -48,6 +48,8 @@ class GetRuleProcessor {
return new OnboardingProfileRuleProcessor();
case 'is_ecommerce':
return new IsEcommerceRuleProcessor();
case 'is_wooexpress':
return new IsWooExpressRuleProcessor();
case 'base_location_country':
return new BaseLocationCountryRuleProcessor();
case 'base_location_state':

View File

@ -0,0 +1,73 @@
<?php
/**
* Rule processor that passes (or fails) when the site is on the eCommerce
* plan.
*
* @package WooCommerce\Admin\Classes
*/
namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications;
defined( 'ABSPATH' ) || exit;
/**
* Rule processor that passes (or fails) when the site is on the eCommerce
* plan.
*/
class IsWooExpressRuleProcessor implements RuleProcessorInterface {
/**
* Passes (or fails) based on whether the site is a Woo Express plan.
*
* @param object $rule The 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 ) {
if ( ! function_exists( 'wc_calypso_bridge_is_woo_express_plan' ) ) {
return false === $rule->value;
}
// If the plan is undefined, only check if it's a Woo Express plan.
if ( ! isset( $rule->plan ) ) {
return wc_calypso_bridge_is_woo_express_plan() === $rule->value;
}
// If a plan name is defined, only evaluate the plan if we're on the Woo Express plan.
if ( isset( $rule->plan ) && wc_calypso_bridge_is_woo_express_plan() ) {
if ( function_exists( 'wc_calypso_bridge_is_woo_express_' . (string) $rule->plan . '_plan' ) ) {
$fn = 'wc_calypso_bridge_is_woo_express_' . (string) $rule->plan . '_plan';
return $fn() === $rule->value;
} elseif ( function_exists( 'wc_calypso_bridge_is_ecommerce_' . (string) $rule->plan . '_plan' ) ) {
$fn = 'wc_calypso_bridge_is_ecommerce_' . (string) $rule->plan . '_plan';
return $fn() === $rule->value;
} else {
// If an invalid plan name is given, only evaluate the rule if we're targeting all plans other than the specified (invalid) one.
return false === $rule->value;
}
}
return false;
}
/**
* Validate 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->plan ) ) {
if ( ! function_exists( 'wc_calypso_bridge_is_woo_express_plan' ) ) {
return false;
}
}
return true;
}
}

View File

@ -411,6 +411,22 @@ This passes when the store is on a WordPress.com site with the eCommerce plan.
`value` is required.
### Is Woo Express
This passes when the store is on a WordPress.com site with a Woo Express plan active.
You can optionally pass the `plan` name to target a specific Woo Express plan, e.g. `performance`.
```
{
"type": "is_ecommerce",
"plan": "trial|essential|performance"
"value": true
}
```
`value` is required.
`plan` is optional, e.g. `trial`, `essential`, `performance`.
### Base location - country
This passes when the store is located in the specified country.