Jump to content

code for upsell redirect if product in shop has a form enabled.

Recommended Posts

Posted

Site URL: https://www.epicureansandiego.com/shop/epic-canvas-tote

Hi y'all, 

I'm trying to get a redirect to an upsell page in our shop when people click "add to cart" on our products. ** Full disclosure, I am not a coder of any sorts and found the code below from SQSP Themes.

When I add the code  to this product, it works perfectly. 

When I try to add it to this product, it never actually adds the original item to the cart before redirecting to the upsell page. I'm thinking its because I have a form attached to that product at checkout for a gift message that is preventing it from working properly. I removed the code from here for the time being so I can continue to sell this item flawlessly, but I'd like to get it back up asap. 

Any help to work around the form would be appreciated!!

Thanks so much!

I used this code from SQSP Themes:

<!-- Redirect to Upsell Page after clicking on Add To Cart Button -->
<!-- Author: Dmitry Kiselyov @_dmitrykiselyov -->
<script>
// /upsell-page is the default URL. To change it, replace /upsell-page with the required URL.
var upsellPageUrl = "/before-you-go"
////////////////////////////////
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"),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 Upsell Page after clicking on Add To Cart Button -->

 

  • Replies 5
  • Views 663
  • Created
  • Last Reply

Top Posters In This Topic

  • 1 year later...

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.