Adding New Variables to window.checkoutConfig on Magento 2 checkout

Adding New Variables to window.checkoutConfig on Magento 2 checkout

We frequently need to add some custom variables to the window.checkoutConfig which we can use during checkout for implementing some custom functionality in Magento 2. Today, we will learn how we can achieve this.

First of all,  we need to add di.xml in view/frontend folder and add the following code to it-

After this, we will create NewVariables.php in Scommerce/AdditionalVars/Model folder and add the following code to it –

That is all. The Variable has been added to window.checkoutConfig and you can access it by window.checkoutConfig.new_var in your js on checkout page, and it will return “New Value“. Just Do not forget to flush the Magento cache.

This is all for now.

For any queries, comment below. 🙂

Discover more from WHO WILL CARE eCommerce

Subscribe now to keep reading and get access to the full archive.

Continue reading