0

I have a webshop in 5 languages now and we sell and ship our products all over Europe. I've made custom checkout fields in WooCommerce without problems.

For 1 country (Norway) we need to add an extra field (PID number). That's no problem, but it should only be visible for Norway. All other countries shouldn't see this custom checkout field.

How do we make a custom checkout field for 1 Country only?

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41

2 Answers2

0

You can use Checkout Field Editor (Checkout Manager) for WooCommerce plugin to achieve your functionality for adding an consditional field on checkout.

Hritik Pandey
  • 899
  • 7
  • 17
  • Hi Hritik Pandey. Thanks for your answer but I do not want to use a(nother) plugin as I've setup my other fields without a plugin. –  Feb 03 '20 at 08:55
0

First, follow the How to Add a Custom Checkout Field tutorial to add a new field to the checkout page. It seems you already got that covered (either manually or through a plugin).

Then, use this jQuery snippet on the checkout page to show and hide your custom field depending on the selected country.

<script>
$(document).ready(function (){

    if ($('#your_country_selet_id').val() == 'your_field_val'){
        $('#newfield').show();
    }

    $('#your_country_selet_id').on('change',function() {
            if ($('#your_country_selet_id').val() == 'your_field_val'){
            $('#newfield').show();  
        } else {
        $('#newfield').hide();

        }
    })
})
</script>
Marcel Stör
  • 22,695
  • 19
  • 92
  • 198
rajat.gite
  • 450
  • 2
  • 10
  • Thanks. I'll try this one out! –  Feb 03 '20 at 15:38
  • Hi Rajat. Tried your script but does not work on my site. Maybe I do not understand your code correctly. What value do you mean with: 1) #your_country_select_id 2) your_field_val 3) #newfield –  Feb 04 '20 at 09:16