woocommerce 获取属性值列表 [英] woocommerce get list of attribute values

查看:50
本文介绍了woocommerce 获取属性值列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 wordpress 上使用 woocommerce 创建一个简单的商店网站,并且我为产品添加了几个属性.它们分别是 sizecolor.在 size 下,我有多种值,包括 Small、Medium 和 Large.与颜色相同,即.红、蓝、绿.

I'm using woocommerce on wordpress to create a simple shop site and I've added a couple attributes to a product. These are namely, size and color. Under size I have a variety of values including Small, Medium and Large. Same with color ie. Red, Blue, Green.

我想要做的是在下拉列表中显示这些值.基本上只需列出它们,以便我可以将这些值用作商店目录页面的过滤器.

What I want to do is show these values in a dropdown. Basically just list them out so I can use the values as filters for the shop catalog page.

任何帮助都会很棒.

我已经深入研究了 woocommerce 代码和 api 文档,只找到了这段代码来提取属性.

I've delved into the woocommerce code and api docs and only found this code to pull the attributes.

global $woocommerce;

$attr_tax = $woocommerce->get_attribute_taxonomy_names();

foreach( $attr_tax as $tax ) {
     echo $woocommerce->attribute_taxonomy_name( $tax->attribute_name );
}

这个片段给我的只是分类slugs,即.pa_size 和 pa_color.我对 woocommerce 很陌生,但是在那里的 api 文档中搜索并没有揭示如何提取这些属性的值.

What this snippet gives me are the taxonomy slugs only, ie. pa_size and pa_color. I'm very new to woocommerce, but a search in there api docs reveals nothing about how to pull the values of these attributes.

推荐答案

您可以使用 get_terms() https://developer.wordpress.org/reference/functions/get_terms/

如果您传入 pa_size 或 pa_color,您将返回该分类法中的术语列表.

If you pass in pa_size or pa_color you will get back a list of terms in that taxonomy.

这篇关于woocommerce 获取属性值列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆