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 [2016/08/17 11:42] – adam | 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 28: | Line 33: | ||
| Inside this block tag you'll place your own custom logic and HTML. The most common use case is that of offering an link or form to add an extra product into the customers cart, unless they already have the product in their cart. That approach could look simply like this: | Inside this block tag you'll place your own custom logic and HTML. The most common use case is that of offering an link or form to add an extra product into the customers cart, unless they already have the product in their cart. That approach could look simply like this: | ||
| - | < | + | < |
| {% 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!</ | ||
| - | < | + | < |
| {% endif %} | {% endif %} | ||
| {% endblock %} | {% endblock %} | ||
| Line 45: | 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 ==== | ||
| + | |||
| + | * If your store has link and form encryption enabled, any add to carts you include within the modal will also need to be encrypted. [[v: | ||
| + | * Any images that you include within your markup need to be served securely. If you're not already using a remote custom template that you're caching, you can have the image cached manually as [[v: | ||
| ===== Step 2: Enable Upsells ===== | ===== Step 2: Enable Upsells ===== | ||
| Line 66: | Line 76: | ||
| If you set '' | If you set '' | ||
| + | |||
| + | ===== Step 3: Taking it further ===== | ||
| + | |||
| + | You have complete control over what logic the Twig includes, and what HTML is output within the modal window. As with any FoxyCart templates, you can also include any custom styles you need - meaning you can create very complex and beautiful upsell displays for your store. | ||
| + | |||
| + | Some examples of more advanced set ups you could take: | ||
| + | |||
| + | * Use a custom session attribute to track if a customer has already added or declined an upsell product. This could be done by sending 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 '' | ||
| + | |||
| + | ==== 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 %} | ||
| + | </ | ||