1 year ago

#360418

test-img

Max

Adding product info from iframe to sqaurespace cart

I am attempting to add product details from an iframe to the cart on the parent page. I am using Squarespace and I cant find any information on how to do this with Javascript.

I added an event listener and I am getting the product details sent from the iframe to the console but need to take that info and add it directly to the cart on squarespace.

          <script>  
          var addToCartBTN = document.querySelector('.sqs-add-to-cart-button')
          window.addEventListener("message", function(e) {
             if(e.data.action == "add-to-cart") {
             console.log("Hello World"); 
             var quant = e.data.quantity;
             console.log(quant);
             console.log(e);
             addToCartBTN.click();
 
        fetch('?format=json-pretty').then(function (response) {
              return response.json(); 
               }).then(function (obj) {
                console.log(obj);    
               })
                 }
           })

javascript

iframe

squarespace

0 Answers

Your Answer

Accepted video resources