Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors

BaseLocationCountryRuleProcessor::process()publicWC 1.0

Performs a comparison operation against the base location - country.

Method of the class: BaseLocationCountryRuleProcessor{}

No Hooks.

Return

true|false. The result of the operation.

Usage

$BaseLocationCountryRuleProcessor = new BaseLocationCountryRuleProcessor();
$BaseLocationCountryRuleProcessor->process( $rule, $stored_state );
$rule(object) (required)
The specific rule being processed by this rule processor.
$stored_state(object) (required)
Stored state.

BaseLocationCountryRuleProcessor::process() code WC 9.0.1

public function process( $rule, $stored_state ) {
	$base_location = wc_get_base_location();
	if (
		! is_array( $base_location ) ||
		! array_key_exists( 'country', $base_location ) ||
		! array_key_exists( 'state', $base_location )
	) {
		return false;
	}

	$onboarding_profile   = get_option( 'woocommerce_onboarding_profile', array() );
	$is_address_default   = 'US' === $base_location['country'] && 'CA' === $base_location['state'] && empty( get_option( 'woocommerce_store_address', '' ) );
	$is_store_country_set = isset( $onboarding_profile['is_store_country_set'] ) && $onboarding_profile['is_store_country_set'];

	// Return false if the location is the default country and if onboarding hasn't been finished or the store address not been updated.
	if ( $is_address_default && OnboardingProfile::needs_completion() && ! $is_store_country_set ) {
		return false;
	}

	return ComparisonOperation::compare(
		$base_location['country'],
		$rule->value,
		$rule->operation
	);
}