0

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?

1

2 Answers 2

0

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?

0
  1. Create the file named di.xml in the path and add below code
    app/code/MyCompany/MyModule/etc/di.xml

    <type name="Magento\Checkout\Block\Checkout\LayoutProcessor"> <plugin name="mycompany_mymodule_remove_street_address" type="MyCompany\MyModule\Plugin\RemoveStreetAddressField" /> </type> 
  2. Create the Onepage.php file in the path app/code/MyCompany/MyModule/Plugin/RemoveStreetAddressField.php

    <?php namespace MyCompany\MyModule\Plugin; use Magento\Checkout\Block\Checkout\LayoutProcessorInterface; class RemoveStreetAddressField { public function afterProcess( LayoutProcessorInterface $subject, array $result ) { if (isset($result['components']['checkout']['children']['steps']['children']['shipping-step']['children'] ['shippingAddress']['children']['shipping-address-fieldset']['children']['street'])) { // Remove street address field unset($result['components']['checkout']['children']['steps']['children']['shipping-step']['children'] ['shippingAddress']['children']['shipping-address-fieldset']['children']['street']); // Remove required attribute from street address field $result['components']['checkout']['children']['steps']['children']['shipping-step']['children'] ['shippingAddress']['children']['shipping-address-fieldset']['children']['street']['validation']['required-entry'] = false; } return $result; } } 

3.Run the below commands and check.
php bin/magento s:d:c

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.