Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Remove Payment Gateways From WooCommerce?

WooCommerce offers a variety of payment gateways to facilitate online transactions. However, for businesses that primarily offer express store pickup as their only delivery method, displaying all available payment gateways can create unnecessary complexity and confusion for customers. In such cases, it is better to remove all payment gateways as store owners prefer to accept cash as a payment method for local pickup items.

This post will help you to remove payment gateways from the WooCommerce checkout page.

Where to Add Custom Code in WooCommerce?

It is advisable to add the code snippets to the functions.php file of your child theme. Access the file directly from Appearance->Theme File Editor->Locating the child theme’s functions.php from the right sidebar. You can also access it from your theme’s directory file. Insert the following code snippet in functions.php. The alternative & easy option is to install & activate the Code Snippets plugin. You can then add the code as a new snippet via the plugin.

Solution: Remove the Payment Gateways From WooCommerce

Consider an online clothing store that primarily serves customers in its local area. They offer local pickup as the only shipping method and want to prevent customers from trying to pay online for their orders. With the below snippet, you can able to remove the payment gateways from WooComerce.

 add_filter('woocommerce_cart_needs_payment', '__return_false');

Output

When the customer adds a product to their cart and proceeds to checkout, the payment gateways are removed from the Checkout WooCommerce page.

How to Remove Payment Gateways From WooCommerce? - Tyche Softwares
How to Remove Payment Gateways From WooCommerce? - Tyche Softwares

Easily Set Fees & Discounts For Payment Gateways

Finding it difficult to manage all payment gateway fees and adjusting your product pricing accordingly?

The Payment Gateway Based Fees & Discounts plugin is designed to set up fees & discounts for each of your payment modes and simplify your payment process.

Code Explanation

Let’s break down the snippet to understand its purpose:-

  • add_filter: This function is used to add a filter to a specific hook.
  • woocommerce_cart_needs_payment‘: This is the hook to which the filter is being added. In WooCommerce, hooks are points in the code where you can add your own custom code. The woocommerce_cart_needs_payment hook is typically used to determine whether the cart needs payment or not.
  • __return_false: This is a special function that simply returns the value false. In the context of filters, using __return_false means that the original value that the filter is modifying will be replaced with false.

Remove Validation of WooCommerce Checkout fields for Payment Gateways

In the above code, even though the payment gateways have been removed from the checkout page, the validation part still doesn’t allow you to place an order. So, we need to skip the validation process for the payment gateways. Let’s set the payment method of an order to an empty value. And this allows shoppers to successfully place an order without requiring a payment method to be selected or validated.

Note: Add the following code in addition to the code provided above to your child theme’s functions.php file

add_action('woocommerce_checkout_order_processed', 'ts_skip_payment_method_validation', 10, 1);

function ts_skip_payment_method_validation($order_id) {
    $order = wc_get_order($order_id);
    $order->set_payment_method(''); // Set no payment method
    $order->save();
}

Conclusion

This code snippet can simplify the checkout process for local pickup orders. And, if your store offers other shipping methods, you can enable/disable a specific payment method based on certain conditions such as disable payment method for specific category @WooCommerce checkout or enable a WooCommerce payment method when the order total is above a certain value.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
2 Comments
Newest
Oldest
Inline Feedbacks
View all comments
Willem
2 months ago

Hi Prateek,

After I implemented the code, the payment option disappeared as it was supposed to. But the notice “no payment option selected” still pops up, prohibiting the order from proceeding. Do you have a line of code for that?

2 months ago
Reply to  Willem

Hi Willem,

We have updated the post according to your request. Please find the code below the heading ‘Remove Validation for Checkout fields with Payment Gateways’.

2
0
Would love your thoughts, please comment.x
()
x