Also Purchased
The also_purchased tag pair helps build “customers also purchased” product suggestions.
Given a product entry_id, it finds other product entry IDs that appeared in the same historical orders, then outputs those related product entries.
This tag is commonly used on product detail pages.
See also:
Parameters
entry_id
The product entry ID used as the source product.
Required for useful output.
entry_id="43"
limit
Maximum number of related products returned.
If omitted, implementation defaults to 20.
limit="3"
variable_prefix
Optional variable prefix for nested templates to avoid naming conflicts.
variable_prefix="also_purchased_"
Variables
In addition to loop variables, this tag outputs related product entry variables (for example {title}, {url_title}, custom product fields, and path variables like {entry_id_path=...}).
entry_id
Entry ID of the related product.
{entry_id}
43
count
Current row index in the result list (starts at 1).
{count}
total_results
Total rows in the current related-product result list.
{total_results}
switch
Alternates values per row.
{switch='odd|even'}
Conditionals
{if no_results}
Displays alternate content if no related products are found.
{if no_results}No related products found{/if}
Behavior and Constraints
- Requires historical order-item data in
cartthrob_order_itemsto produce results. - Uses co-occurrence by order: products from the same orders as the source
entry_idare candidates. - Excludes the source
entry_idfrom results. - If
entry_idis missing, no results are returned. - If CartThrob
orders_channelis not configured, no results are returned. - Only related products that can be resolved to product entry variables are output.
Examples
Basic related IDs:
{exp:cartthrob:also_purchased entry_id="41" limit="3"}
You might also like: {entry_id}<br />
{/exp:cartthrob:also_purchased}
Render related products with normal product variables:
{exp:cartthrob:also_purchased entry_id="41" limit="3"}
{embed="product/detail" entry_id="{entry_id}"}
{/exp:cartthrob:also_purchased}
Nested-template example with variable prefix:
{exp:cartthrob:also_purchased entry_id="{entry_id}" limit="7" variable_prefix="also_purchased_"}
{if count==1}
<h5>Customers Also Purchased</h5>
<ul>
{/if}
<li>
<a href="{path='store/product_detail/{also_purchased_entry_id}'}">{also_purchased_title}</a>
</li>
{if count==total_results}
</ul>
{/if}
{/exp:cartthrob:also_purchased}