Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0

Referring to two different upsell pages, depending on the specific product


FaellesGro

Question

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 

Link to post
  • Answers 3
  • Created
  • Last Reply

Top Posters For This Question

Top Posters For This Question

Popular Posts

On product Additional Info you can add the code block, make it redirect to different upsell page per product

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), a

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

3 answers to this question

Recommended Posts

  • 0
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

Greeting, it's BaNgan from BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement: Enable Pinch/Zoom on lightbox, 360 Degree Photo block, Seperator Block (SVG Shape divider for sections)
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

Link to post

Create an account or sign in to comment

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


×
×
  • Create New...