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 clipboard

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?, 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.

Related posts

Comments

Suscríbete
Notificar de
0 Comments
Más antiguos
Más recientes Más votados

In this post

Products and services

Latest posts

Latest comments

Subscribe!

Lista de correos de APG

DATA PROTECTION: In accordance with data protection regulations, we provide you with the following processing information: (+)

  • Responsible: Art Project Group.
  • Treatment purposes: to respond to queries or any type of request made by the user through any of the forms of contact that are made available on the website. Sending communications about products or services (with your consent).
  • Your rights: access, rectification, portability, deletion, limitation and opposition. More information about the treatment in the Privacy Policy.

What we post on !

Se ha publicado #WooCommerce 11.2.2: actualización de seguridad que refuerza las API REST y Store, mejora la validación de CSV y corrige problemas en pagos y pedidos. Incluye cambios en la base de datos.

¡Actualiza cuanto antes!

November 5, 2026