If you want to prevent out-of-stock products from appearing, you need to exclude them from the cart layout, and add a filter to the trigger to check that at least one in-stock item is included β to prevent you from sending an empty email.
In order to hide out-of-stock products, we must be collecting the stock quantity or status. If you're unsure whether product stock is being captured for your website, contact Support.
Use the Products rule
Go to Triggers in the left side menu.
Expand the Show options (three dots) menu for the trigger you want to edit and select the Edit icon.
βExpand the Raised Browse/Cart Abandon Signal rule group and drag the Products rule to the top of the rule tree on the right, so it's the first entry.
Select the rule to configure and set the options to
all of
Stock
Out of Stock
respectively.
If a cart matches that criteria, this means all of the items in it are of out of stock, so you don't want to send.
Select the Add Trigger Program tab and drag the Do Nothing trigger into the Yes branch. Then add any other rules/triggers to the No branch.
This works to decide whether to add the person to the trigger program initially. If you also want to check before sending each stage of a multi-stage trigger, you need to enable the Refresh product data at send time option and add the following script to the script box that relates to the stage.
result.proceed = false;
if (helpers.checkCartStock() === true){
result.proceed = true;
}
Here's an example applied to the 2nd stage email:
Cart Layout
To hide out-of-stock products in a cart layout, modify the product FOR loop and append the below IF statement:
{% for product in products if product.stock > 0 %}
If you are using an existing filter to limit the number of products returned, you would append the IF statement to the end as follows:
{% for product in products|limit(1)|reverse if product.stock > 0 %}