Ad

How To Add A Gift To An Abandon Cart Email For Shopify

- 1 answer

I am currently sending out abandon cart emails to my potential customers that allows them to click a button in the email and have it take them back to their cart in my store so they can complete the transaction. I would like to modify this button to include the addition of a "Free Gift" (a product on the store). So when the button gets clicked, all of their previous cart items appear in the cart as well as the Free Gift.

The current return to cart button in the email is scripted like so:

<td align="center"><a class="button-link " target="_blank" rel="nofollow noreferrer" href="{{return_url}}" target="_blank" style="background-color: #ffff00; border-radius: 20px; color: #000000; display: inline-block; text-align: center; text-decoration: none; width: 50%; -webkit-text-size-adjust: none; box-sizing: border-box;"><span class="button_content" style="padding: 14px; display: block;"><span style="display: block; font-family: Arial, Helvetica, sans-serif; color: #ad8c8f; font-size: 16px; text-decoration: none;"></span><span style="display: block; font-family: Arial, Helvetica, sans-serif; font-size: 16px; text-decoration: none;"><span style="color: #000000;"><span style="font-size: 2ns-serif; font-size: 16px; text-decoration: none;"><span style="color: #000000;"><span style="font-size: 20px;">Teleport To My&nbsp;Cart!</span></span></span><span style="display: block; font-family: Arial, Helvetica, sans-serif; color: #ad8c8f; font-size: 16px; text-decoration: none;"></span></span></a></td>

I have tried creating a Shopify "Buy Button" to add the free gift: https://dealdigger.myshopify.com/cart/26676652359:1?channel=buy_button however, this just seems to open a whole new shopping cart for the customer and not add it to the already existing shopping cart.

Is there a way to modify the current return to cart button in the email to add the free gift above? Thank you for your help, much appreciated! :)

Ad

Answer

You can use this logic - https://help.shopify.com/themes/customization/cart/use-permalinks-to-preload-cart & https://help.shopify.com/themes/liquid/objects/line_item

Here's a simple code:

{% for item in cart.items %}
  {% capture existing_cart %}{{ existing_cart }}{{ item.variant_id }}:{{ item.quantity }}&{% if forloop.last %}26676652359:1;{% endunless %}{% endcapture %}
{% endfor %}

Now the cart url along with free gift is

https://dealdigger.myshopify.com/cart/{{ existing_cart}}

Ad
source: stackoverflow.com
Ad