Automattic\WooCommerce\Internal\Admin\Suggestions

PaymentsExtensionSuggestions::get_country_extensions │ public │ WC 1.0

Get the list of payment extensions details for a specific country.

The list is memoized per user, country, and context for the duration of the request. Use clear_cache() to force a rebuild.

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

Хуков нет.

Возвращает

array. The list of payment extensions (their full details) for the given country. Empty array if no extensions are available for the country or the country is not supported.

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

$PaymentsExtensionSuggestions = new PaymentsExtensionSuggestions();
$PaymentsExtensionSuggestions->get_country_extensions( $country_code, $context ): array;
$country_code(строка) (обязательный)
The two-letter country code.
$context(строка)
The context ID of where these extensions are being used.
По умолчанию: ''

Код PaymentsExtensionSuggestions::get_country_extensions() WC 11.2.1

public function get_country_extensions( string $country_code, string $context = '' ): array {
	$country_code = strtoupper( $country_code );

	// Key on the user since incentive visibility and dismissals are user-specific.
	$memo_key = get_current_user_id() . '__' . $country_code . '__' . $context;
	if ( isset( $this->country_extensions_memo[ $memo_key ] ) ) {
		return $this->country_extensions_memo[ $memo_key ];
	}

	if ( empty( $this->country_extensions[ $country_code ] ) ||
		! is_array( $this->country_extensions[ $country_code ] ) ) {

		$this->country_extensions_memo[ $memo_key ] = array();
		return $this->country_extensions_memo[ $memo_key ];
	}

	// Process the extensions.
	$processed_extensions = array();
	$priority             = 0;
	foreach ( $this->country_extensions[ $country_code ] as $key => $details ) {
		// Check the formats we support.
		if ( is_int( $key ) && is_string( $details ) ) {
			$extension_id              = $details;
			$extension_country_details = array();
		} elseif ( is_string( $key ) && is_array( $details ) ) {
			$extension_id              = $key;
			$extension_country_details = $details;
		} else {
			// Just ignore the entry as it is malformed.
			continue;
		}

		// Determine if the extension should be included based on the store's state, the provided country and context.
		if ( ! $this->is_extension_allowed( $extension_id, $country_code, $context ) ) {
			continue;
		}

		// Determine the extension details for the given country.
		$extension_base_details = $this->get_extension_base_details( $extension_id ) ?? array();
		$extension_details      = $this->with_country_details( $extension_base_details, $extension_country_details );

		// Apply any changes to the extension details based on the store's state.
		$extension_details = $this->with_store_state_details( $extension_id, $extension_details );

		// Check if there is an incentive for this extension and attach its details.
		$incentive = $this->get_extension_incentive( $extension_id, $country_code, $context );
		if ( is_array( $incentive ) && ! empty( $incentive ) ) {
			$extension_details['_incentive'] = $incentive;
		}

		// Include the extension ID.
		$extension_details['id'] = $extension_id;

		// Lock in the priority for ordering purposes.
		// We respect the order in the country extensions list.
		// We use increments of 10 to allow for easy insertions.
		$priority                      += 10;
		$extension_details['_priority'] = $priority;

		$processed_extensions[] = $this->standardize_extension_details( $extension_details );
	}

	$this->country_extensions_memo[ $memo_key ] = $processed_extensions;

	return $processed_extensions;
}