From 85f55d07fc83cccf0385dec5dc48ef4da2e570d3 Mon Sep 17 00:00:00 2001 From: Manos Psychogyiopoulos Date: Fri, 29 Sep 2023 15:52:09 +0300 Subject: [PATCH] Introduce Woo Express RIN rule --- .../GetRuleProcessor.php | 2 + .../IsWooExpressRuleProcessor.php | 73 +++++++++++++++++++ .../Admin/RemoteInboxNotifications/README.md | 16 ++++ 3 files changed, 91 insertions(+) create mode 100644 plugins/woocommerce/src/Admin/RemoteInboxNotifications/IsWooExpressRuleProcessor.php diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/GetRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/GetRuleProcessor.php index 8cbdb618d81..7f1b195c003 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/GetRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/GetRuleProcessor.php @@ -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': diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/IsWooExpressRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/IsWooExpressRuleProcessor.php new file mode 100644 index 00000000000..9a1ef8d055e --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/IsWooExpressRuleProcessor.php @@ -0,0 +1,73 @@ +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; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/README.md b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/README.md index e2063fe95d2..c93a3616f94 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/README.md +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/README.md @@ -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.