Automattic\WooCommerce\Internal\Admin\Suggestions

PaymentExtensionSuggestions::get_country_extensions()publicWC 1.0

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

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

Хуков нет.

Возвращает

Массив. 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.

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

$PaymentExtensionSuggestions = new PaymentExtensionSuggestions();
$PaymentExtensionSuggestions->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.
По умолчанию: ''

Код PaymentExtensionSuggestions::get_country_extensions() WC 9.6.1

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

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

		return array();
	}

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

		$extension_base_details = $this->get_extension_base_details( $extension_id ) ?? array();
		$extension_details      = $this->with_country_details( $extension_base_details, $extension_country_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 );
	}

	return $processed_extensions;
}