Add to Cart button

If you want to add Add to cart to a standard button block, you can do these.

#1. First, use this code to Code Injection > Footer

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>console.log('Script loaded');$(window).on('load',function(){console.log('Window loaded');$(document).on('click','a',function(e){var $clickedButton=$(this);var buttonUrl=$clickedButton.attr('href');if($clickedButton.hasClass('sqs-block-button-element')&&buttonUrl&&buttonUrl.indexOf('/store/')!==-1){console.log('Button from section 1 clicked:',buttonUrl);e.preventDefault();var originalText=$clickedButton.text();$clickedButton.text('Adding...');$clickedButton.css('pointer-events','none');console.log('Opening hidden iframe for product page:',buttonUrl);var iframe=document.createElement('iframe');iframe.style.display='none';iframe.style.width='0px';iframe.style.height='0px';iframe.style.border='none';iframe.style.position='absolute';iframe.style.left='-9999px';iframe.src=buttonUrl;document.body.appendChild(iframe);iframe.onload=function(){console.log('Product page loaded in iframe');setTimeout(function(){try{var iframeDoc=iframe.contentDocument||iframe.contentWindow.document;var $addToCartButton=$(iframeDoc).find('.sqs-add-to-cart-button');if($addToCartButton.length>0){console.log('Add to cart button found in iframe, clicking...');$addToCartButton[0].click();setTimeout(function(){$clickedButton.text('Added!');document.body.removeChild(iframe);console.log('Product added to cart successfully');setTimeout(function(){location.reload()},1500)},2000)}else{console.log('Add to cart button not found in iframe');$clickedButton.text(originalText);$clickedButton.css('pointer-events','auto');document.body.removeChild(iframe)}}catch(e){console.log('Cross-origin error accessing iframe:',e.message);$clickedButton.text(originalText);$clickedButton.css('pointer-events','auto');document.body.removeChild(iframe)}},1500)};iframe.onerror=function(){console.log('Error loading product page in iframe');$clickedButton.text(originalText);$clickedButton.css('pointer-events','auto');document.body.removeChild(iframe)};setTimeout(function(){if(document.body.contains(iframe)){console.log('Timeout reached, removing iframe');$clickedButton.text(originalText);$clickedButton.css('pointer-events','auto');document.body.removeChild(iframe)}},10000)}})});</script>
You need to login to see the full content. Or send me an email to [email protected], I will send you code.
Buy me a coffee