4

I would like to remove "Region" from all the address forms (checkout, billing address, shipping address, customer's addressbook). I've set the Backend setting for "Allow to Choose State if It is Optional for Country" to No (under Stores > Configuration > General > General, State Options), but the State Option still gets displayed on the Frontend, but is disabled.

What would be the the right way to remove region option from the address forms?


If I update the Backend settings to:

State is Required for: remove all selected country from here.

Allow to Choose State if It is Optional for Country: Set it as "No"

does not remove the Region (Bundesland/Provinz) on the forms, it only disables it.

enter image description here

2 Answers 2

5

If you want disable Region from the address, you have to set below option like.

State is Required for : remove all selected country from here.

Allow to Choose State if It is Optional for Country : Set it as "No"

You can also remove it from "add new address" in customer account.

Copy file form vendor/magento/module-customer/view/frontend/templates/address/edit.phtml

add it in your theme. You can remove region from here for customer add new address.

Save configuration, remove var folder.

12
  • If I unset all options for the "State is Required for" and save it, the options do not get saved. @S H Patel can you save "no values" for this attribute?
    – knospe
    Nov 22, 2016 at 9:50
  • it required any one country, you can select any one country which is not use for store. Nov 22, 2016 at 9:58
  • This does not remove the region option on the frontend, but it only disables it.
    – knospe
    Nov 22, 2016 at 10:02
  • You mean required false ? Nov 22, 2016 at 10:03
  • Following your instructions would make the "region" field not required, but the field would still be displayed on the frontend. My question was how to remove the field, meaning it would not be displayed on the frontend.
    – knospe
    Nov 22, 2016 at 10:11
1

You can hide country and region inside your plugins app/code/company/Magento_Theme/Plugin/Checkout/Block/LayoutProcessor.php

This does not remove it but makes it invisible so close enough from a users point of view for checkout.

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


$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
['children']['shippingAddress']['children']['shipping-address-fieldset']['children'] 
['region']['visible'] = false; // I think it's region...

Or could modify it in the DB possibly, but some of the forms for customer addressbook are still hard coded in template theme. Search in files for the label, make a copy of it as needed in your theme and make it style="display: none;" ?

Urgh.... why...

Can also say State is Required for and uncheck the country in the Store COnfig

https://www.magestore.com/magento-2-tutorial/removedisable-magento-2-state-option/

To set up the state options in Magento 2 you need to follow these steps:

On the Admin sidebar, tap Stores. Then under Settings, choose Configuration. In the panel on the left under General, choose General.

Expand the State Options section, and do the following:

a, In the State is required for list, select each country where Region/State is > a required entry.

b, Set the Allow to Choose State if it is Optional for Country field to one of > the following:

Yes In countries where the state field is not required, includes the State > field as an optional entry. No In countries where the state field is not required, omits the State field. When complete, tap Save Config .

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.