Automattic\WooCommerce\Internal\Admin\Settings
PaymentsProviders::group_gateways_by_extension
Group payment gateways by their plugin extension filename.
Метод класса: PaymentsProviders{}
Хуков нет.
Возвращает
Массив. The grouped payment gateway instances, keyed by the plugin file. Each group contains an array of payment gateway instances that belong to the same plugin. If a payment gateway does not have a corresponding plugin file, it will be grouped under the 'unknown_extension' key.
Использование
// private - только в коде основоного (родительского) класса $result = $this->group_gateways_by_extension( $gateways, $country_code ): array;
- $gateways(WC_Payment_Gateway[]) (обязательный)
- The list of payment gateway instances to group.
- $country_code(строка)
- The country code for which the gateways are being generated. This should be an ISO 3166-1 alpha-2 country code.
По умолчанию:''
Код PaymentsProviders::group_gateways_by_extension() PaymentsProviders::group gateways by extension WC 10.8.1
private function group_gateways_by_extension( array $gateways, string $country_code = '' ): array {
$grouped = array(
// This is the group for gateways that we don't know how to group by extension.
// It can be used for gateways that are not registered by a WP plugin.
'unknown_extension' => array(),
);
foreach ( $gateways as $gateway ) {
// Get the payment gateway details, but use a dummy gateway order since it is inconsequential here.
$gateway_details = $this->get_payment_gateway_details( $gateway, 0, $country_code );
// If we don't have the necessary plugin details, put it in the unknown group.
if ( empty( $gateway_details ) || ! isset( $gateway_details['plugin'] ) || empty( $gateway_details['plugin']['file'] ) ) {
$grouped['unknown_extension'][] = $gateway;
continue;
}
if ( empty( $grouped[ $gateway_details['plugin']['file'] ] ) ) {
$grouped[ $gateway_details['plugin']['file'] ] = array();
}
$grouped[ $gateway_details['plugin']['file'] ][] = $gateway;
}
return $grouped;
}