Skip to content
Advertisement

Hide COD payment based on chosen select field options in WooCommerce checkout

I am using WooCommerce and I have a custom checkout field in form of a selection list. I am trying to remove COD gateway, when customer select on a custom checkout field a specific option (“newyork” in this case).

Here below is my actual code where I don’t know how to make the IF statement condition part working:

JavaScript

How can I get the selected value of my custom checkout field In my code, to get my IF statement working?


Edit:

The custom checkout field id is wc_billing_field_7789 generated by a plugin…

Advertisement

Answer

UpdatedHandling multiple not allowed destinations…

First, for testing I here is a hooked function that displays a custom checkout select field with few options:

JavaScript

See below the display:

enter image description here


Now to get this working jQuery and Ajax are required, to be able to make “Cod” payment enabled or disabled depending on the selected option value from this custom checkout select field.

With this code when “Naeem” or “Other one” are be selected, it will hide “Cash on delivery” (cod) payment method… If another option is selected, “Cash on delivery” will be visible again.

Here is this code:

JavaScript

Code goes in function.php file of your active child theme (or active theme). Tested and works.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement