Selectively disabling payment gateways in WooCommerce

September 20, 2017 · Filed under Web Development, WooCommerce

I recently wrapped up a big WooCommerce project that required quite a bit of customization. I’ve decided to write about a few of those customizations and share code snippets.

Here’s a Scenario

The companies that process credit card transactions charge a fee to do so. It’s usually a flat amount plus a small percentage of the transaction. It’s why sometimes at locally owned gas stations you will see “$5 minimum card purchase” signs. This is a cost of doing business that is usually built into the amount something costs—but what if you have a product that costs a lot of money and is so low margin that the fees will eat up any profit you’ll make? That might sound like an edge scenario, but it’s actually pretty common for certain types of businesses. The solution is to disable credit cards and force the purchaser to use an ACH transfer gateway.

With WooCommerce it is simple to selectively disable gateways based on the total amount of a cart. Check it out:

Here we are checking to see the total amount and if it is above $3000 we are disabling gateway_name. Of course, change gateway_name to the name of your credit card gateway when using this code and the total amount.