产品页面下方的相关产品推荐功能
Brooklyn主题在产品页面默认是没有相关产品推荐功能的。不过这一功能对提高每个客户的订单金额又是至关重要的一环。如果你的产品相关/互补性比较高,强烈建议要实现这一功能。比方说你卖的是宠物用品相关产品,当客户将项圈添加到购物车之后,很有可能会依据你的推荐将狗粮,狗窝一起加入到购物车里面购买。
Shopify有很多的App支持这一功能,你可以安装试用,比较好用的几款都是付费的。你也可以通过下面修改代码的方式给Brooklyn主题添加相关产品推荐功能。
首先打开Template文件夹下面的product.liquid文件,找到如下代码:
{% section ‘product-template’ %}
在这一行代码的下方插入如下代码:
{% section ‘related-products’ %}
然后点击保存文件。
然后打开Section文件夹,点击Add a new section
命名新建的section文件名称为related-products,删除文件里面的已有的所有内容
将文章底部中的代码粘贴到上面的related-products文件里面保存
完成代码添加之后保存文件。现在已经设置好Shopify支持在产品页面显示相关产品功能了,但是这一功能还未被激活,下一步操作就是激活这一功能。
打开shopify后台 – theme – theme editor,打开网站的任意产品页面,在左侧边栏就可以看到Related products选项,然后选择 Show related products 保存就完成设置了。
{% if section.settings.show_related_products == true %}
<hr>
<div class="product-template__container page-width" itemscope itemtype="http://schema.org/Product" id="ProductSection-{{ section.id }}" data-section-id="{{ section.id }}" data-section-type="product" data-enable-history-state="true">
{% comment %}
Number of related items per row,
and number of rows.
{% endcomment %}
{% assign number_of_related_products_per_row = section.settings.related_grid_num %}
{% assign number_of_rows = section.settings.related_grid_row %}
{% comment %}
Heading.
Leave blank if you don't need one.
{% endcomment %}
{% assign heading = section.settings.related_title %}
{% comment %}
Set either or both to true, if you want
to limit yourself to items with same vendor, and/or type.
{% endcomment %}
{% assign same_vendor = false %}
{% assign same_type = false %}
{% comment %}
Collections to ignore.
Never pick related items from those.
{% endcomment %}
{% assign exclusions = 'frontpage,all' | split: ',' %}
{% comment %}
Looking for a relevant collection.
{% endcomment %}
{% if product.metafields.c_f['Related Products'] %}
{% assign collection = collections[product.metafields.c_f['Related Products']] %}
{% endif %}
{% assign found_a_collection = false %}
{% if collection and collection.all_products_count > 1 %}
{% unless exclusions contains collection.handle %}
{% assign found_a_collection = true %}
{% endunless %}
{% endif %}
{% unless found_a_collection %}
{% for c in product.collections %}
{% unless exclusions contains c.handle or c.all_products_count < 2 %}
{% assign found_a_collection = true %}
{% assign collection = c %}
{% break %}
{% endunless %}
{% endfor %}
{% endunless %}
{% comment %}
If we have a relevant collection.
{% endcomment %}
{% if found_a_collection %}
{% assign counter = 0 %}
{% assign break_at = number_of_rows | times: number_of_related_products_per_row %}
{% assign current_product = product %}
{% case number_of_related_products_per_row %}
{% when '1' %}
{% assign grid_item_width = '' %}
{% when '2' %}
{% assign grid_item_width = 'large--one-half medium--one-half' %}
{% when '3' %}
{% assign grid_item_width = 'large--one-third medium--one-half' %}
{% when '4' %}
{% assign grid_item_width = 'large--one-quarter medium--one-third small--one-half' %}
{% when '5' %}
{% assign grid_item_width = 'large--one-fifth medium--one-third small--one-half' %}
{% when '6' %}
{% assign grid_item_width = 'large--one-sixth medium--one-third small--one-half' %}
{% else %}
{% assign grid_item_width = 'large--one-quarter medium--one-third small--one-half' %}
{% endcase %}
{% capture related_items %}
{% for product in collection.products %}
{% unless product.handle == current_product.handle %}
{% unless same_vendor and current_product.vendor != product.vendor %}
{% unless same_type and current_product.type != product.type %}
{% include 'product-grid-item' %}
{% assign counter = counter | plus: 1 %}
{% if counter == break_at %}
{% break %}
{% endif %}
{% endunless %}
{% endunless %}
{% endunless %}
{% endfor %}
{% endcapture %}
{% assign related_items = related_items | trim %}
{% unless related_items == blank %}
<aside class="grid">
<div class="grid__item">
{% unless heading == blank %}
<header class="section-header">
<h2 class="section-header__title">{{ heading }}</h1>
</header>
{% endunless %}
<div class="grid-uniform">
{{ related_items }}
</div>
</div>
</aside>
{% endunless %}
{% endif %}
</div>
{% endif %}
{% schema %}
{
"name": "Related products",
"settings": [
{
"type": "checkbox",
"id": "show_related_products",
"label": "Show related products",
"default": false
},
{
"id": "related_title",
"type": "text",
"label": "Section title",
"default": "Other fine products"
},
{
"type": "select",
"id": "related_grid_num",
"label": "Products per row (Desktop)",
"default": "4",
"options": [
{
"value": "2",
"label": "2"
},
{
"value": "3",
"label": "3"
},
{
"value": "4",
"label": "4"
},
{
"value": "5",
"label": "5"
}
]
},
{
"type": "select",
"id": "related_grid_row",
"label": "Number of rows (Desktop)",
"default": "1",
"options": [
{
"value": "1",
"label": "1"
},
{
"value": "2",
"label": "2"
},
{
"value": "3",
"label": "3"
}
]
}
]
}
{% endschema %}