---
title: "How do you limit the payment method according to the province?"
description: "A few days ago a client asked us that, for the Autonomous Cities of Ceuta and Melilla and the Autonomous Community of the Canary Islands, customers be obliged to pay through PayPal, solely and exclusively through this payment method, so"
url: https://artprojectgroup.com/how-to-limit-the-payment-method-according-to-the-province
date: 2015-12-29
modified: 2023-02-11
author: "Art Project Group"
image: https://artprojectgroup.com/wp-content/uploads/2023/04/woocommerce-blog.webp
categories: ["Tutorials"]
tags: ["functions.php", "PHP", "WooCommerce"]
type: post
lang: en-US
---

# How do you limit the payment method according to the province?

A few days ago a client asked us that, for the Autonomous Cities of Ceuta and Melilla and the Autonomous Community of the Canary Islands, customers be obliged to pay through PayPal, solely and exclusively through this payment method, so PayPal had to be the only means of payment available to customers resident in these Spanish provinces.

Well then, to make it possible we made a small PHP function that checks whether the customer resides in any of the four provinces requested: Ceuta, Melilla, Las Palmas or Santa Cruz de Tenerife, and that removes from the list of available payment methods all those that are not equal to PayPal. Specifically in their case the payment methods with the IDs *cod* (Cash on delivery), *bacs* (Bank transfer) and *cheque* were removed, although other custom payment methods such as *myredsys*, for example, can be added.

Specifically the PHP function we added to the *functions.php* file of the client’s child theme was this:

Copy to clipboardSyntax Highlighterfunction apg_paypal( $medios_de_pago ) {
global $woocommerce;

if ( WC()->customer->get_state() == 'CE' || WC()->customer->get_state() == 'ML' || WC()->customer->get_state() == 'GC' || WC()->customer->get_state() == 'TF' ) {
unset( $medios_de_pago[ 'cod' ] );
unset( $medios_de_pago[ 'bacs' ] );
unset( $medios_de_pago[ 'cheque' ] );
}
return $medios_de_pago;
}
add_filter( 'woocommerce_available_payment_gateways', 'apg_paypal' );
Obviously, for it to be fully functional you have to add a small piece of code included in the entry [How do you add a NIF or CIF field with validation to WooCommerce 2.4?](/how-to-add-a-nif-or-cif-field-with-validation-to-woocommerce-2-4), specifically the addition of the *update_totals_on_change* class to the *state* field, which will make the available payment methods update when the province is changed.

We hope you find this code useful for some of your current or future projects.
