Jump to content

Redirect to specific URL after add-to-cart

Recommended Posts

  • Replies 6
  • Views 1.1k
  • Created
  • Last Reply

Top Posters In This Topic

  • 2 weeks later...
  • 1 year later...
  • 4 months later...
On 6/1/2022 at 3:19 AM, Guest41 said:

I just found this post but do need a solution for this.

Add this to Settings > Advanced > Code Injection > Header:

<!-- Redirect to Page after clicking on 'Add To Cart' Button -->
<script>
// /upsell-page is the default URL. To change it, replace /upsell-page with the required URL.
var upsellPageUrl = "/upsell-page"
////////////////////////////////
function redirectToUpsellPageHandler(wrapper){var addToCartButton=wrapper.querySelector(".sqs-add-to-cart-button"),productVariants=wrapper.querySelector(".product-variants");function isVariantInStock(){return productVariants.getAttribute("data-variant-in-stock")}function onClick(){(productVariants&&isVariantInStock()||!productVariants)&&setTimeout((function(){document.location.href=upsellPageUrl}),1200)}addToCartButton&&addToCartButton.addEventListener("click",onClick)}function redirectToUpsellPage(){var productPage=document.querySelector(".collection-type-products.view-item #productDetails, .collection-type-products.view-item .ProductItem-details:not(.ProductItem-details--mobile)"),productBlocks;productPage&&redirectToUpsellPageHandler(productPage),[].slice.call(document.querySelectorAll(".sqs-block-product")).forEach(redirectToUpsellPageHandler)}document.addEventListener("DOMContentLoaded",redirectToUpsellPage),window.addEventListener("mercury:load",redirectToUpsellPage);
</script>
<!-- end Redirect to page after clicking on Add To Cart Button -->

 

Edited by likemindedproductions
Correct HTML
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.