Gift Wrap option in Cart drawer

Highlighted
Tourist
8 0 1

Hi,

I followed this tutorial to add the gift wrap option to my site: 

https://help.shopify.com/en/themes/customization/cart/add-gift-wrap-option

 

It's working correctly on the cart page.

https://www.lewisishome.com/cart

 

As part of my new theme, I am using a cart drawer which appears on "add to cart" from both the category and product pages. This overlays on the page you're currently on.

 

If I try to add the gift-wrap snippet in the cart drawer {% include 'gift-wrapping' %} when the user clicks the checkbox to add gift wrapping, they are redirected to the cart page, which is unintuitive.

 

I see the reason for this is because there is code to redirect to cart within the code in the snippet.

 

Shopify.Cart.GiftWrap.set = function() {
  jQuery.ajax({
    type: 'POST',
    url: '/cart/update.js', 
    data: { updates: { {{ id }}: 1 }, attributes: { 'gift-wrapping': true } }, 
    dataType: 'json',
    success: function() { location.href = '/cart'; }
  });
}

Shopify.Cart.GiftWrap.remove = function() {
  jQuery.ajax({
    type: 'POST',
    url: '/cart/update.js', 
    data: { updates: { {{ id }}: 0 }, attributes: { 'gift-wrapping': '' } }, 
    dataType: 'json',
    success: function() { location.href = '/cart'; }
  });
}

Is there any way work around to this? Ideally the functionality would stay exactly the same, but the new gift wrap product would appear in the cart drawer on the same page.

 

Thanks very much in advance,

Jenny

0 Likes