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,756
  • 6
  • 18
  • 38

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
  • 821
  • 5
  • 16
  • 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

you can follow this tutorial for add custom field How to Add a Custom Checkout Field

<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>

then use this jquery for hide and show your custom field on checkout page

rajat.gite
  • 409
  • 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