2

I tried to hide the country field in the checkout page and billing page. Here's my code :

<item name="region_id" xsi:type="array">
    <item name="visible" xsi:type="boolean">false</item>
    <item name="config" xsi:type="array">
        <item name="componentDisabled" xsi:type="boolean">true</item>
    </item>
</item>
<item name="country_id" xsi:type="array">
    <item name="visible" xsi:type="boolean">false</item>
</item>

I could do checkout when i remove this code :

<item name="country_id" xsi:type="array">
    <item name="visible" xsi:type="boolean">false</item>
</item>

But, when i remove it, the country field still appeared. How can i hide the country field? I can't hide with CSS because the class for country field is class="field _required"

3
  • why do you want to remove?
    – Amit Bera
    Sep 28, 2018 at 4:20
  • cause it's only in my country, and it should be default choose only 1 country Sep 28, 2018 at 6:10
  • .fieldset.address div[name="shippingAddress.country_id"] {display: none;} Feb 15, 2022 at 18:55

1 Answer 1

4

You can do this using plugin:

  $visible = [
       'visible' => false
       ];

  $country = &$jsLayout['components']['checkout']['children']['steps'] 
 ['children']['shipping-step']
['children']['shippingAddress']['children']['shipping-address-fieldset'] 
 ['children']['country_id'];

  $street = array_merge($country, $visible);
3
  • 1
    @AdityaShah @ Rutvee please be kind to each other. You are both wonderful people for helping out others with answers to their questions Sep 28, 2018 at 9:42
  • hi @RutveeSojitra, i tried your pluggin, but it made the checkout page just blank, is there something wrong i did? Oct 1, 2018 at 7:09
  • It's work for me, you just need to pass ['children']['company']['visible'] = false if you want to hide company field. +1 for this :) Sep 3, 2019 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.