in ,

Enable/Disable Payment Methods By Country On WooCommerce

Customise Payment Methods For WooCommerce Based On Country

WooCommerce is the largest open source e-commerce platform out there that supports hundreds of payment gateways. However, when serving to an international customer base, it’s important to provide them with the payment methods that they’re comfortable with, to ensure a smooth check-out experience for them and avoid missing a sale!

In this article, I’m going to show you how you can easily customize the check-out experience on your store for your international audience, by offering them the payment method they’re comfortable with, based on the country they’re shopping from.

Steps To Customize WooCommerce Payment Gateways Based On Countries

Method 1: Using Plugin

We’ll use a plugin which lets you disable selected payment gateways/methods based on the country the user is visiting from, and also make some payment methods exclusively available to specific countries.

The plugin is called Woo Disable Payment Methods By Countries.

Step 1: Installing The Plugin

Firstly, download the plugin from here: Woo Disable Payment Methods By Countries

Installing the “Disable Payment Methods By Countries” plugin for WooCommerce is similar to the installation of any usual WordPress plugin.

Here’s a step-by-step guide to help you install the plugin after downloading the zip file:

  1. Log in to your WordPress admin dashboard. This is typically accessed by adding “/wp-admin” to your domain name (e.g., www.yourdomain.com/wp-admin).
  2. Once you’re logged in, navigate to the left-hand side menu and click on “Plugins” and then “Add New.” You’ll be taken to the “Add Plugins” page.
  3. On the “Add Plugins” page, click on the “Upload Plugin” button located at the top of the page.
  4. Next, click on the “Choose File” button and browse your computer to select the zip file you downloaded for the “Disable Payment Methods By Countries” plugin. After selecting the file, click on the “Install Now” button.
  5. WordPress will now upload and install the plugin. Once the installation is complete, you’ll see a success message. Click on the “Activate Plugin” link to activate the plugin.
  6. After activating the plugin, you’ll be redirected to the “Plugins” page, where you’ll find the “Disable Payment Methods By Countries” plugin listed among your installed plugins.

Step 2: Configuring The Plugin

After the plugin is installed and activated, you’ll find the Disable Payment Gateways option under the WordPress Settings from the left hand side menu bar.

Clicking on the Disable Payment Gateways option from under Settings, will take you to the page shown above.

Here, under the Payment Gateway column, you’ll find a list of all the payment methods that are currently active on your site.

Under the second column – Blocked Countries, you can type the country codes for each plugin, where they need to be blocked.

Under the third column – Inverse Selection, you can enable the option if you want that payment method to be exclusively accessible from only the selected countries.

Using a combination of the options under the second and third columns, it is possible to create any desired combination of payment methods for any country to ensure that all your visitors find an easy and localized checking-out experience

This method is recommended for most store owners and developers who are creating websites for clients, as it doesn’t require any changes to be made in the code, and everything can be controlled using a simple graphical user interface (GUI).

Method 2: Using Code

To block certain payment methods for specific countries on WooCommerce using a custom PHP code, follow the instructions provided below.

PHP Code To Block Specific Payment Methods For Specific Countries on WooCommerce

add_filter('woocommerce_available_payment_gateways', 'block_payment_methods_for_countries');

function block_payment_methods_for_countries($available_gateways) {
    // Define a dictionary of country codes and blocked payment methods
    $blocked_countries = array(
        'US' => array('paypal', 'stripe'),
        'CA' => array('stripe'),
        'AU' => array('paypal')
    );

    // Get the customer's country code
    $customer_country = WC()->customer->get_billing_country();

    // Check if the customer's country is in the blocked countries dictionary
    if (array_key_exists($customer_country, $blocked_countries)) {
        $blocked_methods = $blocked_countries[$customer_country];

        // Remove specific payment methods for blocked countries
        foreach ($blocked_methods as $method) {
            unset($available_gateways[$method]);
        }
    }

    return $available_gateways;
}

To modify the code, you need to change the values in the $blocked_countries array. This will work on the basis of the get_billing_country of the customer.

This method is suitable only for stores owned by developers themselves, as making any changes to the functionality would require direct modification of the code, which is not recommended for those unfamiliar with PHP.

That’s all! Now your store is all set and ready to serve a customized and localized check-out experience to its visitors all around the globe!

If you have any queries, feel free to comment down below, and I’ll try my best to help you out!

What do you think?

Written by Anirban Roy

Anirban is a full-stack developer and an SEO expert. He has 6 years of experience in web development and software engineering. With a passion for writing, he has been blogging since 2017.

Leave a Reply

Your email address will not be published. Required fields are marked *