0

I need to add button in mini cart just below the "Proceed to checkout" button. And the button is loaded using this javascript code:

let sourceUrl = "{some_url/index.js}";
let scriptEle = document.createElement("script");
scriptEle.setAttribute("src", sourceUrl);
scriptEle.setAttribute("type", "module");
document.head.append(scriptEle);
const buttonHolder = document.getElementById('button-container');
let myButton = document.createElement("my-button");
buttonHolder.appendChild(myButton);

The code in magento/module-checkout/view/frontend/web/template/minicart/content.html is responsible for the view in mini cart. I tried some methods to create javascript files and somehow insert this button but unfortunately couldn't. I am a beginner to Magento 2. How can I make this thing possible?

1 Answers1

0

try this

const buttonHolder = document.getElementById('button-container');
let myButton = document.createElement("button");
myButton.id = 'my-button'
buttonHolder.appendChild(myButton);

var script   = document.createElement("script");
script.type  = "module";
script.src   = "path/to/your/javascript.jsx";  
document.body.appendChild(script);
perona chan
  • 101
  • 1
  • 8
  • Actually the problem I am facing is I don't know where to put this code, and how will I use it in content.html to render it. The code I provided is working fine. Kindly guide. – Pratik Giramkar Apr 23 '23 at 12:11