The recommendations object

The recommendations object provides product recommendations that are related to a given product, based on data from sales, product descriptions, and relations between products and collections. Product recommendations become more accurate over time as new orders and product data become available. To learn more about how product recommendations work, see Showing product recommendations on product pages.

The recommendations object returns products only if it's used in a theme section that's rendered via /recommendations/products?section_id=<section_id>&product_id=<product_id>, where section_id is the id of the section where the recommendations object is being used, and product_id is the id of the product you want to show recommended products for. In order to show the section, you must make the request using JavaScript and insert the response's markup on the page.

To learn how to implement the recommendations object, see Showing product recommendations on the product page using Liquid.

The recommendations object has the following attributes:

recommendations.performed

Returns true if the recommendations object is referenced inside a theme section that is rendered via /recommendations/products?section_id=<section_id>&product_id=<product_id> with valid parameters:

Parameters for recommendations.performed
Parameters Description Required
product_id id of the product you want to show recommended products for yes
section_id id of the section where the recommendations object is being used yes
limit Limits number of results, up to a maximum of ten no

recommendations.products_count

Returns the number of product recommendations, or returns 0 if recommendations.performed is false.

recommendations.products

Returns product recommendations. These objects are products. Doesn't return any product if recommendations.performed is false.

For example, this Liquid snippet creates the conditions to show product recommendations:

{% if recommendations.performed %}
  {% if recommendations.products_count > 0 %}
    {% for product in recommendations.products %}
      {{ product.title | link_to: product.url }}
    {% endfor %}
  {% endif %}
{% else %}
  <div class="placeholder">Placeholder animation</div>
{% endif %}

It produces the following output when the enclosing section is rendered synchronously:

Placeholder animation

And it produces the following output when the enclosing section is rendered from the endpoint /recommendations/products?section_id=<section_id>&product_id=<product_id>:

Product title
Another product title

Ready to start selling with Shopify?

Try it free