Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| v:2.0:snippets:checkout_upsells [2017/04/26 07:02] – external edit 127.0.0.1 | v:2.0:snippets:checkout_upsells [2025/05/30 21:44] (current) – foxybrett | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| Beginning in version 2.0 we've added some basic upsell functionality into the checkout. It allows you to quickly show a modal window to customers on the checkout providing opportunities for them to add additional products to their cart prior to checkout. | Beginning in version 2.0 we've added some basic upsell functionality into the checkout. It allows you to quickly show a modal window to customers on the checkout providing opportunities for them to add additional products to their cart prior to checkout. | ||
| + | |||
| + | <wrap tip>It also works on subscription cancellations!</ | ||
| The upsell modal window is displayed on page load of the checkout, based on conditions you set within your custom Twig logic. | The upsell modal window is displayed on page load of the checkout, based on conditions you set within your custom Twig logic. | ||
| {{: | {{: | ||
| + | |||
| + | |||
| ===== Step 1: Add custom Twig to your checkout ===== | ===== Step 1: Add custom Twig to your checkout ===== | ||
| Line 31: | Line 35: | ||
| <code html> | <code html> | ||
| {% block upsell_modal %} | {% block upsell_modal %} | ||
| - | {% set hasUpsell | + | {% set showUpsell |
| {% for item in items %} | {% for item in items %} | ||
| {% if item.code == " | {% if item.code == " | ||
| - | {% set hasUpsell | + | {% set showUpsell |
| {% endif %} | {% endif %} | ||
| {% endfor %} | {% endfor %} | ||
| - | {% if not hasUpsell | + | {% if showUpsell |
| < | < | ||
| <p>As a limited time offer, we're offering you this unique product for only $12.95. That's $5 off our normal price!</ | <p>As a limited time offer, we're offering you this unique product for only $12.95. That's $5 off our normal price!</ | ||
| Line 46: | Line 50: | ||
| A few things happens within this code. | A few things happens within this code. | ||
| - | - Firstly, we set a variable called '' | + | - Firstly, we set a variable called '' |
| - | - Next, we loop through the items in the cart and look for any products with a code of '' | + | - Next, we loop through the items in the cart and look for any products with a code of '' |
| - | - Finally, if '' | + | - Finally, if '' |
| ==== Important Notes ==== | ==== Important Notes ==== | ||
| Line 82: | Line 86: | ||
| * On page load of the checkout, you could send off a [[v: | * On page load of the checkout, you could send off a [[v: | ||
| * If you wanted to also trigger the upsell modal off of other events on the checkout - such as removing a product from their cart or clicking a button or link - it can be shown by calling '' | * If you wanted to also trigger the upsell modal off of other events on the checkout - such as removing a product from their cart or clicking a button or link - it can be shown by calling '' | ||
| + | |||
| + | ==== Only showing the upsell window once across customer sessions ==== | ||
| + | |||
| + | If you want to ensure the customer only sees the upsell modal once across multiple different checkout attempts, you can utilise cookies to store details about the customer that can be retrieved in future checkout sessions. As an example, the following code will add a cookie that will last for 30 days if the customer either closes the upsell modal or submits the add to cart form, preventing the customer from seeing it again for that timeframe. | ||
| + | |||
| + | You would include this code in the " | ||
| + | |||
| + | <code javascript> | ||
| + | {% if context == " | ||
| + | < | ||
| + | var upsell_cookie_name = " | ||
| + | cookie_expires_in = 30; // default, in days | ||
| + | |||
| + | $(function() { | ||
| + | var has_upsell_cookie = document.cookie.split(';' | ||
| + | return item.indexOf(upsell_cookie_name + ' | ||
| + | }).length; | ||
| + | if (has_upsell_cookie) { | ||
| + | $(' | ||
| + | if (FC.checkout.upsell_modal) { | ||
| + | FC.checkout.upsell_modal.close(); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | // On closing the modal | ||
| + | $(' | ||
| + | // On submitting a form in the modal | ||
| + | $(' | ||
| + | }); | ||
| + | |||
| + | function addUpsellCookie(days) { | ||
| + | var expires = "", | ||
| + | date = new Date(), | ||
| + | days = parseInt(days); | ||
| + | | ||
| + | if (typeof days !== " | ||
| + | days = cookie_expires_in; | ||
| + | } | ||
| + | |||
| + | date.setTime(date.getTime() + (days*24*60*60*1000)); | ||
| + | expires = "; expires=" | ||
| + | document.cookie = upsell_cookie_name + " | ||
| + | } | ||
| + | </ | ||
| + | {% endif %} | ||
| + | </ | ||
| + | |||
| + | You can modify this script as needed, updating the '' | ||
| + | |||
| + | The script also supports passing a custom cookie length, in days, to the '' | ||
| + | |||
| + | <code javascript> | ||
| + | |||
| + | Finally, you can also comment out either of the event hooks that are triggered on closing the modal or submitting a form, depending on your needs. For example if you only wanted to prevent the upsell from showing again if the customer submits the form, you would comment out this line like this: | ||
| + | |||
| + | <code javascript> | ||
| + | // $(' | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | ===== Displaying a Subscription Cancellation Upsell or Message ===== | ||
| + | |||
| + | All the steps above should be followed, but here's code tailored to display the message based on the '' | ||
| + | |||
| + | <code html> | ||
| + | {% block upsell_modal %} | ||
| + | {% if is_subscription_cancel %} | ||
| + | <div id=" | ||
| + | < | ||
| + | <p>We understand things change, but if you're cancelling because:</ | ||
| + | <ul> | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ul> | ||
| + | < | ||
| + | <div> | ||
| + | <ul> | ||
| + | <li> | ||
| + | <a href=" | ||
| + | </li> | ||
| + | <li> | ||
| + | <a data-remodal-action=" | ||
| + | </li> | ||
| + | </ul> | ||
| + | </ | ||
| + | </ | ||
| + | {% endif %} | ||
| + | {% endblock %} | ||
| + | </ | ||