How to Get Payment Gateways Programmatically
Looking for WooCommerce payment plugin development? Let me help you.
First of all, if you go to WooCommerce > Settings > Payments, you can find all the installed payment gateways there.

Here I will show you how to work with two class methods:
WC()->payment_gateways()->payment_gateways()
,- and
WC()->payment_gateways()->get_available_payment_gateways()
What is the difference? 🤔 You will find out in a second.
payment_gateways() – Allows to Get All the Installed Payment Methods
By default WooCommerce has 4 installed payment gateways: BACS, Check Payments, Cash on Delivery and PayPal. The additional payment methods can be installed with plugins. Usually if plugin is activated = the gateway is installed and you can find it in the shop settings.
This class method returns objects of all payment gateways installed on your WooCommerce store. Want to get custom payment gateway data? Just print_r()
the result and you’ll have it.
$installed_payment_methods = WC()->payment_gateways()->payment_gateways();
echo '<pre>'; print_r( $installed_payment_methods ); echo '</pre>';
Here is my example:
In the below example let’s try to print the names of payments gateways:
$installed_payment_methods = WC()->payment_gateways()->payment_gateways();
foreach( $installed_payment_methods as $method ) {
echo $method->title . '<br />';
}
Some of WC_Payment_Gateway methods will also be available, example:
$installed_payment_methods = WC()->payment_gateways()->payment_gateways();
foreach( $installed_payment_methods as $method ) {
echo $method->get_title() . '<br />'; // print methods titles
}
You can also find some mysterious “Misha Gateway” on my screenshots 🙃 Okay, it is a custom payment gateway I created in a separate tutorial.
This function also has a filter woocommerce_payment_gateways
. This filter runs on the early stage and allows you to completely remove any of WooCommerce default payment gateways.
get_available_payment_gateways() – Get Only Available Gateways
WooCommerce uses this function when it gets the payment methods directly on the checkout page and while processing payment.
So, for example, if a specific payment method is not enabled in the shop settings, it won’t be shown.
$available_payment_methods = WC()->payment_gateways()->get_available_payment_gateways();
The return result is similar to WC()->payment_gateways()->payment_gateways()
. It also has a filter woocommerce_available_payment_gateways
.
Get Selected Payment Method
Here is how you can get a payment method slug (ID) from user session.
$selected_payment_method_id = WC()->session->get( 'chosen_payment_method' );
// 'bacs', 'cod', 'cheque', 'paypal' etc
Ok now, but how to get the selected payment gateway title or other custom data?
$selected_payment_method_id = WC()->session->get( 'chosen_payment_method' );
$selected_payment_method = WC()->payment_gateways()->payment_gateways()[ $selected_payment_method_id ];
// print_r( $selected_payment_method );

Misha Rudrastyh
Hey guys and welcome to my website. For more than 10 years I've been doing my best to share with you some superb WordPress guides and tips for free.
Need some developer help? Contact me
Hi
Very interesting post !
Question : How can i use these functions to for BACS payment on a certain amount (eg Bacs payment when the amount of the checkout is legal or superior to 250€ ?
Many thank !
Regards
Phil
…i would say : force BACS payment when the amount of checkout is ≥ to 250€ (sorry for my poor english)
Hi!
The only thought now is to do it in JavaScript :)
Hi..
I’m taking an error.
My code;
How can I fix it? Thanks..
Hi,
When this error happens?
Hi.
I’m tring to add custom field all payment gateways.
Maybe you use it in a wrong place.
hi is there a way to put the payment gateways to other page? other than checkout page?
Hi Nick,
I tried to do something like this but it leads to many bugs and problems. I even have a plugin for it, but I won’t sell it anymore until I find a 100% working solution.
Hi,
How i can change payment position. In my case i want to add payment option after checkout fields. If anyone know how to do this please let me know here.
Thanks
Hi Misha!
thx for the guide.
I would like to enable payment methods also if no payment is needed (free cuopon for example).
in this case, misha_change_wc_gateway_if_empty ins’t called, so I can’t enable this payment gateways.
Any suggestion?
Thanks!
Very interesting.
Q: How can hide some checkout billing field when certain gateway is checked?
Thank you, and god work!
Hi Jorge,
Sure, we gonna use the code from the chechout fields tutorial too.
The example of code that hide the billing company checkout field:
Excelent!
But HTTP ERROR 500.
thanks
I fixed the code.
Only need hide one billing_field on checkout page
Ex:
If i click on Payment_method ‘PayPal’
Need hide a field ‘billing_VAT’
Is possible?
Ok, I understand what you mean. Just one question, is billing_VAT a required field for another payment gateway?
Hi Misha
Yes, is a required field from another payment method.
Only need hide/unset for all other methods
Thank you
Ok, some jQuery code should help you in this case, but please note that you do not have to include jQuery because it is already included in your checkout page:
But before using it make sure that your billing field ID is
#billing_vat_field
and the payment method ID ispaypal
. You can do it just in your browser – Right click, then Inspect.To insert the JS code you can also use
wp_footer
hook.Hi Misha,
now i’m confused. Lol
jquery is already included, because i try your code in footer.
This new code can insert in function.php ?
Yes 🙃
jQuery is not necessary because it is included by WooCommerce, just insert this code to the functions.php
Hi Misha, what a nice job you’re doing here.
I am trying to create a plugin that allows users to pay via Alipay which is not supported in my country. However, there is an Alipay partner company here in Nigeria that already gave me their API but the problem is, I couldn’t figure out how to enable user/buyer pay either by logging in to the Alipay or scanning Alipay QR code.
The documentation provided by the said company is not detailed enough. Can you give me a little direction on how to go about it?
PS: I already know that there are WP Plugins for Alipay crossboarder… but we are not working directly with Alipay we are using one of the partners’ API to allow us accept Alipay in Nigeria.
Thank you.
Hi Akanni,
Thank you!
It is always challenging when the gateway doesn’t provide well documented API. I think you should try to resolve the questions with their support team.
Hi Misha. Thank you for your excellent guide. Is it possible to receive payment with popup form using Woocommerce? Do you have an idea on this?
Hi Ömer,
Yes, why not. I had a plugin for that actually. Now it is temporarily unavailable but it is in my plans to bring it back to life.
Now the correct access it not
WC()->payment_gateways->payment_gateways()
it’s
WC()->payment_gateways()->payment_gateways()
On WordPress 6.0.1 and WooCommerce 6.7.0 both of the methods are working without PHP notices, but I’m agreed with you, that
WC()->payment_gateways()
is more correct.Thank you, updated it in the tut.
Hey Misha,
Thanks for your excellent guides through out my career you are such a life saver ;) Can you please guide me how to integrate custom payment integration form which action is something external website link where payment will made with neccessary parameters. So how I achieve this ?
How I use this form in the checkout form ?