标签搜索

shopify recently viewed products

sunshine
2024-08-15 / 0 评论 / 7 阅读
温馨提示:
本文最后更新于2024年08月15日,已超过34天没有更新,若内容或图片失效,请留言反馈。
    // Save product ID to localStorage, for use in the 'Recently viewed products' section.
    {%- if request.page_type == 'product' %}
      try {
        const items = JSON.parse(localStorage.getItem('cc-recently-viewed') || '[]');

        // If product ID is not already in the recently viewed list, add it to the beginning.
        if (!items.includes({{ product.id | json }})) {
          items.unshift({{ product.id | json }});
        }

        // Set recently viewed list and limit to 12 products.
        localStorage.setItem('cc-recently-viewed', JSON.stringify(items.slice(0, 12)));
      } catch (e) {}
    {%- endif %}
感觉很棒,欢迎点赞 OR 打赏~
0
分享到:

评论 (0)

取消