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 comment

4 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, Delivery Date Picker, Youtube Gallery for Squarespace
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 comment
  • 0

@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 by PHOME
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...