Magento – Magento2 : How to force Shipping Address is the same as Billing Address

billing-addresscheckout-pagemagento2shipping-address

Is there a way to prevent the addition of a different address at checkout, so that billing and shipping addresses are always the same?

With this I'd like to also prevent the user adding a shipping address in their account, and if they already have more than one to hide any but the first. And that updating the billing address also updates the shipping address.

Since I don't believe this is a on/off functionality in the Magento 2 backend I assume this would require and entire module?

Best Answer

Add This code on your header

 <script type="text/javascript">

        require(['jquery'],function($){


                $(document).ready(function () {
                     $(document).ajaxComplete(function () {
                         if($('input#billing-address-same-as-shipping-shared').prop("checked") == true){
                        }else{
                            $('input#billing-address-same-as-shipping-shared').trigger('click');
                        }
                });
            });

        });

    </script>
    <style type="text/css">
        .field._required[name="shippingAddress.city"],.box.box-address-billing { display: none!important; }
        .checkout-billing-address { display: none; }
        /*.checkout-billing-address { pointer-events: none; display: none; }
        input#billing-address-same-as-shipping-shared { opacity: .5; }*/
    </style>
Related Topic