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. 🙂