skip to Main Content

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?

2

Answers


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

    Login or Signup to reply.
  2. 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>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search