WC_Payment_Gateways::get_available_payment_gateways
Get available gateways for checkout.
This should be used when displaying the available gateways/payment methods to the user, not in the WP admin or REST API contexts where there is no WC session. This is because the logic that hooks into the available gateways filter may try to rely on the existence of a WC session - a valid thing to do, and cause fatal errors when the session is not available.
Method of the class: WC_Payment_Gateways{}
Hooks from the method
Returns
Array. The available payment gateways.
Usage
$WC_Payment_Gateways = new WC_Payment_Gateways(); $WC_Payment_Gateways->get_available_payment_gateways();
WC_Payment_Gateways::get_available_payment_gateways() WC Payment Gateways::get available payment gateways code WC 10.5.0
public function get_available_payment_gateways() {
// Early return if fraud protection blocks session.
if ( wc_get_container()->get( FraudProtectionController::class )->feature_is_enabled()
&& wc_get_container()->get( SessionClearanceManager::class )->is_session_blocked() ) {
return array();
}
$_available_gateways = array();
foreach ( $this->payment_gateways as $gateway ) {
if ( $gateway->is_available() ) {
if ( ! is_add_payment_method_page() ) {
$_available_gateways[ $gateway->id ] = $gateway;
} elseif ( $gateway->supports( PaymentGatewayFeature::ADD_PAYMENT_METHOD ) || $gateway->supports( PaymentGatewayFeature::TOKENIZATION ) ) {
$_available_gateways[ $gateway->id ] = $gateway;
}
}
}
return array_filter( (array) apply_filters( 'woocommerce_available_payment_gateways', $_available_gateways ), array( $this, 'filter_valid_gateway_class' ) );
}