Automattic\WooCommerce\Internal\Admin\Settings

PaymentsProviders::get_payment_gatewayspublicWC 1.0

Get the payment gateways for the settings page.

We apply the same actions and logic that the non-React Payments settings page uses to get the gateways. This way we maintain backwards compatibility.

Method of the class: PaymentsProviders{}

Returns

Array. The payment gateway objects list.

Usage

$PaymentsProviders = new PaymentsProviders();
$PaymentsProviders->get_payment_gateways( $for_display, $country_code ): array;
$for_display(true|false)
Whether the payment gateway list is intended for display purposes. This triggers the legacy woocommerce_admin_field_payment_gateways and the exclusion of "shell" gateways.
Default: true
$country_code(string)
The country code for which the payment gateways are being generated. This should be an ISO 3166-1 alpha-2 country code.
Default: ''

PaymentsProviders::get_payment_gateways() code WC 10.7.0

public function get_payment_gateways( bool $for_display = true, string $country_code = '' ): array {
	// Normalize the country code to uppercase.
	$country_code = strtoupper( $country_code );

	// If we are asked for a display gateways list, we need to fire legacy actions and filter out "shells".
	if ( $for_display ) {
		if ( isset( $this->payment_gateways_for_display_memo[ $country_code ] ) ) {
			return $this->payment_gateways_for_display_memo[ $country_code ];
		}

		// We don't want to output anything from the action. So we buffer it and discard it.
		// We just want to give the payment extensions a chance to adjust the payment gateways list for the settings page.
		// This is primarily for backwards compatibility.
		ob_start();
		/**
		 * Fires before the payment gateways settings fields are rendered.
		 *
		 * @since 1.5.7
		 */
		do_action( 'woocommerce_admin_field_payment_gateways' );
		ob_end_clean();

		// Get all payment gateways, ordered by the user.
		$payment_gateways = WC()->payment_gateways()->payment_gateways;

		// Handle edge-cases for certain providers.
		$payment_gateways = $this->handle_non_standard_registration_for_payment_gateways( $payment_gateways );

		// Remove "shell" gateways from the list.
		$payment_gateways = $this->remove_shell_payment_gateways( $payment_gateways, $country_code );

		// Store the entire payment gateways list for display for later use.
		$this->payment_gateways_for_display_memo[ $country_code ] = $payment_gateways;

		return $payment_gateways;
	}

	// We were asked for the raw payment gateways list.
	if ( isset( $this->payment_gateways_memo[ $country_code ] ) ) {
		return $this->payment_gateways_memo[ $country_code ];
	}

	// Get all payment gateways, ordered by the user.
	$payment_gateways = WC()->payment_gateways()->payment_gateways;

	// Handle edge-cases for certain providers.
	$payment_gateways = $this->handle_non_standard_registration_for_payment_gateways( $payment_gateways );

	// Store the entire payment gateways list for later use.
	$this->payment_gateways_memo[ $country_code ] = $payment_gateways;

	return $payment_gateways;
}