Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors

BaseLocationCountryRuleProcessor::process()publicWC 1.0

Performs a comparison operation against the base location - country.

Метод класса: BaseLocationCountryRuleProcessor{}

Хуков нет.

Возвращает

true|false. The result of the operation.

Использование

$BaseLocationCountryRuleProcessor = new BaseLocationCountryRuleProcessor();
$BaseLocationCountryRuleProcessor->process( $rule, $stored_state );
$rule(объект) (обязательный)
The specific rule being processed by this rule processor.
$stored_state(объект) (обязательный)
Stored state.

Код BaseLocationCountryRuleProcessor::process() WC 9.4.2

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
	);
}