0

I want to show one shipping address per login customer in checkout shipping sections. How can I do it in magento 2.

thanks.

1

Copy the file in your local theme from

vendor\magento\module-checkout\view\frontend\web\js\view\shipping-address\list.js

Modify the function ,

        /** @inheritdoc */
        initChildren: function () {

        if(addressList().length > 0){
            this.createRendererComponent(addressList()[0],this); /* It always set the first shipping address. Change the logic as per your requirement */
        }
        else{
            _.each(addressList(), this.createRendererComponent, this);
        }

        return this;
    },

To hide New Address button,

Copy the html template from

vendor\magento\module-checkout\view\frontend\web\template\shipping.html

To the local theme and comment the below code

        <if args="!isFormInline">
            <button type="button"
                    class="action action-show-popup"
                    click="showFormPopUp"
                    visible="!isNewAddressAdded()">
                <span translate="'New Address'" />
            </button>
            <div id="opc-new-shipping-address"
                 visible="isFormPopUpVisible()"
                 render="shippingFormTemplate" />
        </if>
8
  • Updated the code to always get the first shipping address – saravanavelu Apr 18 '18 at 10:08
  • it works but need to disable add new address button. – Lasantha Apr 18 '18 at 11:18
  • Updated the code to remove new address button. – saravanavelu Apr 18 '18 at 11:56
  • @ saravanavelu thanks. are there any way to disable using backend, I have a doubt what can I do when client request to enable it again, – Lasantha Apr 18 '18 at 12:12
  • It is possible to control that from backend by default. need to customize based on your requirement. – saravanavelu Apr 18 '18 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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