Home » WooCommerce: Enable Payment Gateway Only for “Order Pay Checkout”

WooCommerce: Enable Payment Gateway Only for “Order Pay Checkout”

by Tutor Aspire

I invoice clients via WooCommerce, and then send them the “Invoice Email”, which takes them to the “Order Pay” page. Of course, I want to give them the option to pay via “Bank Transfer” (bacs), but I don’t want this to be visible on the default checkout page.

We’ve seen in the past how to disable payment gateways given certain conditions… but how do we “enable” one? Here’s a snippet for that – enjoy!

WooCommerce: enable a payment gateway on the Order Pay page only
WooCommerce: enable a payment gateway on the Order Pay page only

PHP Snippet: Enable Payment Gateway Only for “Order Pay” Page (WooCommerce Checkout)

/**
 * @snippet       Enable payment gateway - WooCommerce Checkout
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 3.6.2
 * @donate $9     https://tutoraspire.com
 */

add_filter( 'woocommerce_available_payment_gateways', 'tutoraspire_enable_gateway_order_pay' );

function tutoraspire_enable_gateway_order_pay( $available_gateways ) {
if ( is_checkout() && ! is_wc_endpoint_url( 'order-pay' ) ) {
   unset( $available_gateways['bacs'] );
}
return $available_gateways;
}

Is There a WooCommerce “Conditional Payment Gateways” Plugin?

If you don’t feel 100% confident with coding, I decided to look for a reliable plugin that achieves the same result of this snippet (and more).

In this case, I found the WooCommerce Conditional Payment Gateways plugin to be the most complete when you need to enable/disable payment gateways based on certain criteria. You can create unlimited “rules” and use, for example, cart totals, billing country, shipping country, user role, checkout page and much more to define which payment gateway shows and which not.

But in case you don’t want to use plugins and wish to code (or wish to try that), then keep reading 🙂

You may also like