4

How to remove State/Province field from the cart page?

I tried using jquery to remove it, that didn't work for me.

<script>
  require(['jquery', 'jquery/ui'], function($){ 

    $(document).ready(function($){
        var checkList = setInterval(function() {
            if($("#shipping-zip-form").length > 0 ){    

                    //$("input[name='shippingAddress.region']").hide();                                     
                    setTimeout(function() {
                        $("input[name='shippingAddress.region']").hide();
                    }, 2000);                               
                    clearInterval(checkList);
                  }
            }, 2000); // check every 1000ms

      });  
  });
 </script>

Is there anyway available to remove it from xml or php code? Please anybody help on this thanks.

2 Answers 2

9

You can do it by following method: Create a file with name checkout_cart_index.xml under

app/design/frontend/Vendor/theme/Magento_Checkout/layout/checkout_cart_index.xml

and add the below code:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="checkout.cart.shipping">
            <arguments>
                <argument name="jsLayout" xsi:type="array">
                    <item name="components" xsi:type="array">
                        <item name="block-summary" xsi:type="array">
                            <item name="children" xsi:type="array">
                                <item name="block-shipping" xsi:type="array">
                                    <item name="children" xsi:type="array">
                                        <item name="address-fieldsets" xsi:type="array">
                                            <item name="children" xsi:type="array">
                                                <item name="region_id" xsi:type="array">
                                                    <item name="config" xsi:type="array">
                                                        <item name="componentDisabled" xsi:type="boolean">true</item>
                                                    </item>
                                                </item>
                                                <item name="region" xsi:type="array">
                                                    <item name="config" xsi:type="array">
                                                        <item name="componentDisabled" xsi:type="boolean">true</item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

Thats it! Need to flush the cache and test.

5
0

what would I need to add to also hide the Country?

And also this removes it from my cart page but the fields still appear on the checkout page, is there a way to remove from checkout page too?

Your Answer

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

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