Automattic\WooCommerce\Internal\Admin\Settings

PaymentProviders::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: PaymentProviders{}

Returns

Array. The payment gateway objects list.

Usage

$PaymentProviders = new PaymentProviders();
$PaymentProviders->get_payment_gateways( $exclude_shells ): array;
$exclude_shells(true|false)
Whether to exclude "shell" gateways that are not intended for display.
Default: true

PaymentProviders::get_payment_gateways() code WC 9.9.3

public function get_payment_gateways( bool $exclude_shells = true ): array {
	if ( ! is_null( $this->payment_gateways_memo ) ) {
		$payment_gateways = $this->payment_gateways_memo;
	} else {

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

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

	// Remove "shell" gateways that are not intended for display.
	// We consider a gateway to be a "shell" if it has no WC admin title or description.
	if ( $exclude_shells ) {
		$payment_gateways = array_filter(
			$payment_gateways,
			function ( $gateway ) {
				return ! empty( $gateway->get_method_title() ) || ! empty( $gateway->get_method_description() );
			}
		);
	}

	return $payment_gateways;
}