Magento 2 How to override “\vendor\magento\module-checkout\view\frontend\web\js\view\billing-address.js” in our custom module?

magento.stackexchange https://magento.stackexchange.com/questions/255316

Question

I want to disable "New Address" option from billing address drop down. here i got the code to disable it.

we just need to comment the below code : addressOptions.push(newAddressOption); and it will disable the option. but I need to override this file in my custom module and need to comment that code.

How can i override "billing-address.js" in my custom module?

Thanks.

Was it helpful?

Solution

For this, you need to create requirejs-config.js under your custom module, let say (VENDOR/MODULE/view/frontend/requirejs-config.js)

In this js file,

var config = {
    map: {
        "*": {
            "Magento_Checkout/js/view/billing-address": "VENDOR_MODULE/js/view/billing-address"
        }
    }
};

please note that VENDOR_MODULE/js/view/billing-address in this file you can write your changes (For testing purpose you can copy the original file and put some log)

After that perform static-content:deploy by executing the command from the magento2 root directory.

php bin/magento s:s:d -f

then clear the cache

php bin/magento cache:clean

OTHER TIPS

If there is a file that already exists that you are trying to override. Go to http\app\design\frontend\company_name\theme and in there you can create Magento_Checkout. Then as long as you get the exact file structure from where the js file is located within module-checkout. So say its within layout, create a layout folder and put it in there. Magento should use the new file instead of the default vendor file.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top