{"id":7398,"date":"2019-10-04T12:36:49","date_gmt":"2019-10-04T07:06:49","guid":{"rendered":"https:\/\/www.hiddentechies.com\/blog\/?p=7398"},"modified":"2019-10-04T15:34:16","modified_gmt":"2019-10-04T10:04:16","slug":"magento-2-add-variable-checkout-page","status":"publish","type":"post","link":"https:\/\/www.hiddentechies.com\/blog\/magento-2\/magento-2-add-variable-checkout-page\/","title":{"rendered":"Magento 2 &#8211; How to Add More Variable to Window.checkoutConfig on Checkout Page"},"content":{"rendered":"<p>Sometimes we need to add some custom variables to the Window.checkoutConfig which we can get on checkout page and can use to implement some custom functionality or develop some custom logic. So here I am going to explain how you can add custom variable to Window.checkoutConfig.<\/p>\n<p>Here, I am using my custom module \u2013 Ht_Mymodule<\/p>\n<p>First, create di.xml in your module and add following code in it.<\/p>\n<p>File Path: app\/code\/Ht\/Mymodule\/etc\/frontend\/di.xml<\/p>\n<pre class=\"lang:default decode:true \">&lt;?xml version=\"1.0\"?&gt;\r\n\r\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:ObjectManager\/etc\/config.xsd\"&gt;\r\n    &lt;type name=\"Magento\\Checkout\\Model\\CompositeConfigProvider\"&gt;\r\n        &lt;arguments&gt;\r\n            &lt;argument name=\"configProviders\" xsi:type=\"array\"&gt;\r\n                &lt;item name=\"more_config_provider\" xsi:type=\"object\"&gt;Ht\\Mymodule\\Model\\Checkout\\MoreConfigProvider&lt;\/item&gt;\r\n            &lt;\/argument&gt;\r\n        &lt;\/arguments&gt;\r\n    &lt;\/type&gt;\r\n&lt;\/config&gt;<\/pre>\n<p>Create MoreConfigProvider.php<\/p>\n<p>File Path: app\/code\/Model\/Checkout\/MoreConfigProvider.php<\/p>\n<pre class=\"lang:default decode:true \">&lt;?php\r\n\r\nnamespace Ht\\Mymodule\\Model\\Checkout;\r\n\r\nclass MoreConfigProvider implements \\Magento\\Checkout\\Model\\ConfigProviderInterface \r\n{\r\n    public function getConfig() {\r\n        $output['custom_data'] = 'your data value';\r\n        return $output;\r\n    }\r\n}<\/pre>\n<p>Now, inside your knockout js file, You can get value like,<\/p>\n<pre class=\"lang:default decode:true \">var customData = window.checkoutConfig.custom_data;\r\nconsole.log(customData);<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes we need to add some custom variables to the Window.checkoutConfig which we can get on checkout page and can use to implement some custom functionality or develop some custom logic. So here I am going to explain how you can add custom variable to Window.checkoutConfig. Here, I am using my custom module \u2013 Ht_Mymodule&#8230; <\/p>\n<div class=\"actions\"><a href=\"https:\/\/www.hiddentechies.com\/blog\/magento-2\/magento-2-add-variable-checkout-page\/\">Continue Reading<\/a><\/div>\n","protected":false},"author":1,"featured_media":7409,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[10,27],"_links":{"self":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7398"}],"collection":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/comments?post=7398"}],"version-history":[{"count":1,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7398\/revisions"}],"predecessor-version":[{"id":7399,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7398\/revisions\/7399"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media\/7409"}],"wp:attachment":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media?parent=7398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/categories?post=7398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/tags?post=7398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}