Magento – Remove street address field and required attribute from shipping address

checkoutmagento2onepage-checkoutshipping-address

I have a very custom use for Magento and I'm trying to remove street address from the checkout. Currently I have:

class LayoutProcessor {
 /**
 * @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
 * @param array $jsLayout
 * @return array
 */
 public function afterProcess(
     \Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
     array  $jsLayout
 ) {
    $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
['shippingAddress']['children']['shipping-address-fieldset']['children']['street'] = [
    'component' => 'Magento_Ui/js/form/components/group',
    'required' => false,
    'dataScope' => 'shippingAddress.street',
    'provider' => 'checkoutProvider',
    'sortOrder' => 1005,
    'type' => 'group'
    ];

     return $jsLayout;
 }
}

Unfortunately, while this seems to have removed the street address and stopped it from being required when entering shipping address, once I continue to the Review & Payment page and press "Place Order" it provides the following error, stopping me from proceeding:

Please check the shipping address information. street is a required field.

How can I stop this check and allow it to proceed?

This solution suggests that I can remove the required aspect of fields with jquery, but where would I put this js file and get magento to load it on the Review and Payment page?

Best Answer

Hmm I'm I think there is no simple solution because the database will need a street. What you could do it create a plugin on GuestShippingInformationManagement (you will also need to do this for the non guest version). And add a fake 'street'. Or make the field hidden and add a default string in the street field?

Related Topic