Automattic\WooCommerce\Internal\Admin\Suggestions
PaymentsExtensionSuggestions::get_country_extensions
Get the list of payment extensions details for a specific country.
Method of the class: PaymentsExtensionSuggestions{}
No Hooks.
Returns
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.
Usage
$PaymentsExtensionSuggestions = new PaymentsExtensionSuggestions(); $PaymentsExtensionSuggestions->get_country_extensions( $country_code, $context ): array;
- $country_code(string) (required)
- The two-letter country code.
- $context(string)
- The context ID of where these extensions are being used.
Default: ''
PaymentsExtensionSuggestions::get_country_extensions() PaymentsExtensionSuggestions::get country extensions code WC 10.3.3
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;
}
// 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 );
}
return $processed_extensions;
}