Step 4: Update your cart
Remove hidden line item properties, or calculate and hide discount messages
Once you have published the checkout script, you should add a product to cart while previewing the lowest priced group. In certain cases, you may notice an issue in the cart when you do this. A few examples of things that may happen include:
There may be a few visible line item properties in the cart
The Intelligems discount message will occasionally show in the cart
The compare-at price will not display correctly in the cart. For example, the compare-at price may show as the control group price, rather than the compare-at price for the test group you are in
Should any of these happen, follow the below corresponding guidance to correct the issue and complete the integration.
Remove Hidden Line Item Properties
Most Shopify stores use a convention that any line item with a leading underscore _
should not be displayed in the cart. The Intelligems line item property (e.g. _igLineItemDiscount
) in the Checkout Script you've just added begins with an underscore, so we will piggyback on this convention to make sure the Intelligems discount line item property is hidden.
Here is a common example of how this is implemented in a liquid cart (e.g. cart-line-items.liquid or a similar file). Many themes already contain this code, but it may be necessary to add if it is not already present. We recommend searching your theme file with a tool like EZFY first to see if similar code already exists.
The key lines are as follows:
This code should be implemented in a loop over each item property. In context, the code block may look something like the below:
You can learn more about this here under 'Hide line item properties (optional)'.
Calculate the Intelligems Discount (per line item and cumulative)
If we're using the Checkout Scripts to apply a "hidden" discount on a product, we don't want to show the user that they're receiving an Intelligems discount. Locate the liquid file that renders each cart item, often called cart-line-items.liquid or something similar. Within that file, locate the beginning of the loop over each item. It will look something like the below:
For each cart item, we'll want to check to see if an Intelligems discount was applied, and we'll want to keep track of the running total of Intelligems discounts. The snippet below under 'New', placed inside an existing code block which iterates over each cart item, will create a variable intelligems_discount per line item which is either 0 or a non-zero number in cents which represents the Intelligems price change. This can also be used to adjust compare-at prices if desired.
Old
New
Note that you'll only need one 'for' loop here (i.e. only one instance of the line "for item in cart.items")
Hide the Strikethrough Price in the Cart
Now that we have each item's Intelligems discount, we can prevent certain item properties (i.e. a strikethrough) from being rendered in the cart.
Within the 'for' loop described above, locate the code that renders the strikethrough price. It may look something like the below:
We might add the condition below to the code rendering the strikethrough:
In context, this will look like something like the below:
Hide the Discount Message
Sometimes discount messages appear to communicate bundle discounts, etc. In this case, we'll want to hide our message. We know from the checkout script in Step 4 that the Intelligems discount has the name "Discount" in most cases, so we'll hide any discount message with this name. Locate the code that renders the discount message, again in the 'for' loop over the cart's items. It will likely look something like the below:
We'll want to add the following condition to prevent "Intelligems" from being rendered as a discount name:
In context, this will look something like the below:
Note: there may be additional adjustments you want to make (e.g. adjusting a strikethrough on the subtotal). We recommend using the line item and running total discount variables you created above and similar conditional logic to implement these additional adjustment.
Integrating Using HandleBars
Follow the example below if you use HandleBars in your theme. Add the HandleBar functions to the rest of your HandleBar functions.
Last updated