FaellesGro Posted March 3, 2021 Share Posted March 3, 2021 Site URL: https://www.faellesgro.dk/vlg-bydel Hi there, I have been working on this for a while now. I have created a page with summary blocks referring to our membership products (see URL), and would now like to redirect customers to two different upselling pages - '/tilkoeb-1' & '/tilkoeb-2', depending on which product, they choose. I have used this code to redirect to an upsell page, when customers click Add To Cart: <!-- Redirect to the Upsell Page after clicking on the Add To Cart button --> <!-- Author: Dmitry Kiselyov @_dmitrykiselyov --> <script> function redirectToUpsellPage() { var upsellPageUrl = '/tilkoeb-1'; var addToCartButton = document.querySelector('.sqs-add-to-cart-button'); var productVariants = document.querySelector('.product-variants'); function isVariantInStock() { return productVariants.getAttribute('data-variant-in-stock'); } function onClick() { if (productVariants && isVariantInStock() || !productVariants) { setTimeout(function() { document.location.href = upsellPageUrl; }, 1000); } } if (addToCartButton) { addToCartButton.addEventListener('click', onClick); } } document.addEventListener('DOMContentLoaded', redirectToUpsellPage); window.addEventListener('mercury:load', redirectToUpsellPage); </script> <!-- end Redirect to the Upsell Page after clicking on the Add To Cart button --> Everything is working fine, when I go in through the specific product URL, as I've split the products on two different product pages and added the code to these pages. But when I go in through the page with the summary blocks, the code isn't working. Is it possible to add the code directly to the specific products - and how? Or can the code be rewritten to refer to specific products/product pages? I hope someone here can help me?? Kind regards, Ida Beyondspace 1 Link to comment
tuanphan Posted March 7, 2021 Share Posted March 7, 2021 Hi. You can contact sqspthemes support. Their support is good Email me if you have need any help (free, of course.). Answer within 24 hours. Or send to forum message Contact Customer Care - Learn CSS - Buy me a coffee (thank you!) Link to comment
Beyondspace Posted March 7, 2021 Share Posted March 7, 2021 On 3/3/2021 at 11:25 PM, FaellesGro said: Site URL: https://www.faellesgro.dk/vlg-bydel Hi there, I have been working on this for a while now. I have created a page with summary blocks referring to our membership products (see URL), and would now like to redirect customers to two different upselling pages - '/tilkoeb-1' & '/tilkoeb-2', depending on which product, they choose. I have used this code to redirect to an upsell page, when customers click Add To Cart: <!-- Redirect to the Upsell Page after clicking on the Add To Cart button --> <!-- Author: Dmitry Kiselyov @_dmitrykiselyov --> <script> function redirectToUpsellPage() { var upsellPageUrl = '/tilkoeb-1'; var addToCartButton = document.querySelector('.sqs-add-to-cart-button'); var productVariants = document.querySelector('.product-variants'); function isVariantInStock() { return productVariants.getAttribute('data-variant-in-stock'); } function onClick() { if (productVariants && isVariantInStock() || !productVariants) { setTimeout(function() { document.location.href = upsellPageUrl; }, 1000); } } if (addToCartButton) { addToCartButton.addEventListener('click', onClick); } } document.addEventListener('DOMContentLoaded', redirectToUpsellPage); window.addEventListener('mercury:load', redirectToUpsellPage); </script> <!-- end Redirect to the Upsell Page after clicking on the Add To Cart button --> Everything is working fine, when I go in through the specific product URL, as I've split the products on two different product pages and added the code to these pages. But when I go in through the page with the summary blocks, the code isn't working. Is it possible to add the code directly to the specific products - and how? Or can the code be rewritten to refer to specific products/product pages? I hope someone here can help me?? Kind regards, Ida On product Additional Info you can add the code block, make it redirect to different upsell page per product tuanphan and FaellesGro 2 BeyondSpace - Squarespace Website Developer 🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox, video lightbox and much more) 🗓️ Delivery Date Picker (Squarespace Date picker form field) 💫 Gallery block 7.1 workaround 🥳 No-code customisations for Squarespace (+100 Spark plugin customisations) 🥳 Freemium Squarespace Widget Templates (+1000 Elfsight Templates) If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you! Link to comment
FaellesGro Posted March 31, 2021 Author Share Posted March 31, 2021 (edited) Thanks for your answers, guys. @bangank36 - I actually tried that before, but now found out the I had to disable Ajax Loading for it to work 🙂 Best, Ida Edited March 31, 2021 by FaellesGro Beyondspace 1 Link to comment
PHOME Posted September 24, 2021 Share Posted September 24, 2021 (edited) @FaellesGro Interested to know if you found a solution for this, am trying to achieve the same thing. I also have a form that customers are required to fill in after press Add to Cart (as they can add personalised text) so that's also causing me some issues. Thanks Edited September 24, 2021 by PHOME Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment