Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders
PaymentGateway::get_provider_links
Get the provider links list.
These are contextual, in general external links aimed to help the user learn more about the payment provider and reach out for help.
Each link is an associative array with '_type' and 'url' keys. The type is a string indicating the type of link, e.g., 'documentation', 'support', 'pricing', etc. The only accepted types are the ones documented in the PaymentsProviders::LINK_TYPE_* constants.
Example: array(
array( '_type' => 'documentation', 'url' => 'https://example.com/docs', ), array( '_type' => 'support', 'url' => 'https://example.com/support', ),
);
Method of the class: PaymentGateway{}
No Hooks.
Returns
Array. The provider links list. Empty array if none are available or an error occurs.
Usage
$PaymentGateway = new PaymentGateway(); $PaymentGateway->get_provider_links( $payment_gateway, $country_code ): array;
- $payment_gateway(WC_Payment_Gateway) (required)
- The payment gateway object.
- $country_code(string)
- The country code for which the providers are being requested. This should be an ISO 3166-1 alpha-2 country code. If invalid, it will be ignored.
Default:''
PaymentGateway::get_provider_links() PaymentGateway::get provider links code WC 10.4.3
public function get_provider_links( WC_Payment_Gateway $payment_gateway, string $country_code = '' ): array {
$country_code = strtoupper( sanitize_text_field( $country_code ) );
// Validate the country code format - expect ISO 3166-1 alpha-2.
// Empty country code is valid (parameter is optional), so only validate non-empty values.
if ( '' !== $country_code && ( strlen( $country_code ) !== 2 || ! ctype_upper( $country_code ) ) ) {
// Log so we can investigate non-empty invalid country codes.
SafeGlobalFunctionProxy::wc_get_logger()->debug(
'Received invalid country code when getting provider links. Ignoring it.',
array(
'gateway' => $payment_gateway->id,
'source' => 'settings-payments',
'country' => $country_code,
)
);
$country_code = '';
}
$provider_links = array();
try {
// Try to get the links list from the payment gateway if it provides such method.
if ( method_exists( $payment_gateway, 'get_provider_links' ) &&
is_callable( array( $payment_gateway, 'get_provider_links' ) ) ) {
$provider_links = call_user_func(
array( $payment_gateway, 'get_provider_links' ),
$country_code
);
// Validate and normalize the links list.
$accepted_types = array(
PaymentsProviders::LINK_TYPE_ABOUT,
PaymentsProviders::LINK_TYPE_DOCS,
PaymentsProviders::LINK_TYPE_SUPPORT,
PaymentsProviders::LINK_TYPE_PRICING,
PaymentsProviders::LINK_TYPE_TERMS,
);
$validated_links = array();
if ( is_array( $provider_links ) ) {
foreach ( $provider_links as $link ) {
if ( ! is_array( $link ) ) {
continue;
}
$type = ( isset( $link['_type'] ) && is_scalar( $link['_type'] ) ) ? sanitize_key( (string) $link['_type'] ) : '';
if ( empty( $type ) || ! in_array( $type, $accepted_types, true ) ) {
continue;
}
if ( empty( $link['url'] ) || ! is_string( $link['url'] ) || ! wc_is_valid_url( $link['url'] ) ) {
continue;
}
$url = sanitize_url( $link['url'] );
// Create a unique key for deduplication (type + URL).
$link_key = $type . '|' . $url;
// Skip if we already have this exact link.
if ( isset( $validated_links[ $link_key ] ) ) {
continue;
}
$validated_links[ $link_key ] = array(
'_type' => $type,
'url' => $url,
);
}
}
$provider_links = array_values( $validated_links );
}
} catch ( Throwable $e ) {
// Do nothing but log so we can investigate.
SafeGlobalFunctionProxy::wc_get_logger()->debug(
'Failed to get provider links: ' . $e->getMessage(),
array(
'gateway' => $payment_gateway->id,
'source' => 'settings-payments',
'exception' => $e,
)
);
return array();
}
return $provider_links;
}