WooCommerce 短代码完全手册:灵活调用产品信息
WooCommerce 提供了强大的短代码功能,让你可以在网站的任意位置调用产品信息。本文整理了最常用的短代码及其使用方法。
一、短代码如何使用
古腾堡编辑器
在编辑文章或页面时,添加一个短代码区块,然后把对应的短代码粘贴进去即可。
经典编辑器
直接复制粘贴短代码到编辑器中。
二、页面短代码
[woocommerce_cart] – 显示购物车页面
[woocommerce_checkout] – 显示结账页面
[woocommerce_my_account] – 显示用户账户页面
[woocommerce_order_tracking] – 显示订单跟踪表单
三、产品展示短代码
基础短代码:[products]
常用参数
limit – 显示产品数量,-1 表示全部
columns – 列数,默认 4
orderby – 排序方式(date、id、popularity、rating、title 等)
order – 升序 ASC 或降序 DESC
category – 指定分类
tag – 指定标签
ids – 指定产品 ID
skus – 指定 SKU
四、实用短代码示例
1. 显示最新产品:[products limit=”4″ columns=”4″ orderby=”date” order=”DESC”]
2. 显示特价产品:[products limit=”4″ columns=”4″ on_sale=”true”]
3. 显示特色产品:[products limit=”4″ columns=”2″ visibility=”featured”]
4. 显示畅销产品:[products limit=”3″ columns=”3″ best_selling=”true”]
5. 显示随机产品:[products limit=”4″ columns=”4″ orderby=”rand”]
6. 显示指定分类产品:[products limit=”8″ columns=”4″ category=”hoodies,tshirts” cat_operator=”IN”]
7. 排除指定分类:[products limit=”8″ columns=”4″ category=”uncategorized” cat_operator=”NOT IN”]
8. 显示指定属性产品:[products columns=”3″ attribute=”season” terms=”warm” orderby=”date”]
9. 显示指定标签产品:[products limit=”12″ columns=”4″ tag=”hoodie”]
10. 显示指定 ID 产品:[products ids=”1,2,3,4″ columns=”4″]
五、产品分类短代码
[product_categories] – 显示所有分类
[product_categories number=”0″ parent=”0″] – 显示顶级分类
[product_category category=”clothing” per_page=”12″ columns=”4″] – 显示指定分类的产品
六、其他实用短代码
[product_page id=”99″] – 显示单个产品
[product_page sku=”FOO”] – 按 SKU 显示产品
[related_products limit=”12″ columns=”4″] – 显示相关产品
总结
掌握这些短代码,你就可以在网站的任何位置灵活展示产品信息,无需编写复杂代码。建议在测试页面先尝试各种组合,找到最适合你网站的展示方式。