Add to Cart to List item v2

To add Add to Cart button to List item, you can do these.

#1. First, we will add a List People Section

#2. Next, we will add image text, url to product

#3. Use this code to Page Header Injection (or 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.closest('.user-items-list-item-container').length>0&&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>

#4. Remember to update Store Page URL

Buy me a coffee