Transformers
1 year ago
BaseLocationCountryRuleProcessor.php
2 years ago
BaseLocationStateRuleProcessor.php
2 years ago
ComparisonOperation.php
2 years ago
ContextPluginsRuleProcessor.php
1 year ago
EvaluateAndGetStatus.php
2 years ago
EvaluateOverrides.php
1 year ago
EvaluationLogger.php
1 year ago
FailRuleProcessor.php
2 years ago
GetRuleProcessor.php
2 years ago
GetRuleProcessorForContext.php
1 year ago
IsEcommerceRuleProcessor.php
2 years ago
IsWooExpressRuleProcessor.php
2 years ago
NotRuleProcessor.php
2 years ago
NoteStatusRuleProcessor.php
2 years ago
OnboardingProfileRuleProcessor.php
2 years ago
OptionRuleProcessor.php
2 years ago
OrRuleProcessor.php
2 years ago
OrderCountRuleProcessor.php
2 years ago
OrdersProvider.php
2 years ago
PassRuleProcessor.php
2 years ago
PluginVersionRuleProcessor.php
2 years ago
PluginsActivatedRuleProcessor.php
2 years ago
ProductCountRuleProcessor.php
1 year ago
PublishAfterTimeRuleProcessor.php
2 years ago
PublishBeforeTimeRuleProcessor.php
2 years ago
RuleEvaluator.php
1 year ago
RuleProcessorInterface.php
2 years ago
StoredStateRuleProcessor.php
2 years ago
StoredStateSetupForProducts.php
2 years ago
TotalPaymentsVolumeProcessor.php
1 year ago
WCAdminActiveForProvider.php
2 years ago
WCAdminActiveForRuleProcessor.php
2 years ago
WooCommerceAdminUpdatedRuleProcessor.php
2 years ago
BaseLocationCountryRuleProcessor.php
71 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Rule processor that performs a comparison operation against the base |
| 4 | * location - country. |
| 5 | */ |
| 6 | |
| 7 | namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; |
| 8 | |
| 9 | use Automattic\WooCommerce\Internal\Admin\Onboarding\OnboardingProfile; |
| 10 | |
| 11 | defined( 'ABSPATH' ) || exit; |
| 12 | |
| 13 | /** |
| 14 | * Rule processor that performs a comparison operation against the base |
| 15 | * location - country. |
| 16 | */ |
| 17 | class BaseLocationCountryRuleProcessor implements RuleProcessorInterface { |
| 18 | /** |
| 19 | * Performs a comparison operation against the base location - country. |
| 20 | * |
| 21 | * @param object $rule The specific rule being processed by this rule processor. |
| 22 | * @param object $stored_state Stored state. |
| 23 | * |
| 24 | * @return bool The result of the operation. |
| 25 | */ |
| 26 | public function process( $rule, $stored_state ) { |
| 27 | $base_location = wc_get_base_location(); |
| 28 | if ( |
| 29 | ! is_array( $base_location ) || |
| 30 | ! array_key_exists( 'country', $base_location ) || |
| 31 | ! array_key_exists( 'state', $base_location ) |
| 32 | ) { |
| 33 | return false; |
| 34 | } |
| 35 | |
| 36 | $onboarding_profile = get_option( 'woocommerce_onboarding_profile', array() ); |
| 37 | $is_address_default = 'US' === $base_location['country'] && 'CA' === $base_location['state'] && empty( get_option( 'woocommerce_store_address', '' ) ); |
| 38 | $is_store_country_set = isset( $onboarding_profile['is_store_country_set'] ) && $onboarding_profile['is_store_country_set']; |
| 39 | |
| 40 | // Return false if the location is the default country and if onboarding hasn't been finished or the store address not been updated. |
| 41 | if ( $is_address_default && OnboardingProfile::needs_completion() && ! $is_store_country_set ) { |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | return ComparisonOperation::compare( |
| 46 | $base_location['country'], |
| 47 | $rule->value, |
| 48 | $rule->operation |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Validates the rule. |
| 54 | * |
| 55 | * @param object $rule The rule to validate. |
| 56 | * |
| 57 | * @return bool Pass/fail. |
| 58 | */ |
| 59 | public function validate( $rule ) { |
| 60 | if ( ! isset( $rule->value ) ) { |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | if ( ! isset( $rule->operation ) ) { |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | return true; |
| 69 | } |
| 70 | } |
| 71 |