php - 通过 WooCommerce 中的 slug 获取产品属性标签名称
问题描述
我已将 product_attributes 创建为:Color
have slug color
/ Size
has slugsize
在产品中:如何color
通过 slug 显示名称/标签。
我尝试 wc_get_product_terms 但它的属性值color / size
不是var_dup(color / size)
信息。
解决方案
您可以通过它的 slug 获取 product_attributes 标签名称,wc_attribute_label()
如下所示:
$attribute_slug = 'color';
$attribute_taxonomy = 'pa_' . $attr_slug;
echo wc_attribute_label( $attribute_taxonomy );
和
$attribute_slug = 'size';
$attribute_taxonomy = 'pa_' . $attr_slug;
echo wc_attribute_label( $attribute_taxonomy );
推荐阅读
- spring - 无法为 Spring Boot Rest Api 启动 Apache Tomcat v9.0 服务器
- typescript - 直接在控制器函数中验证枚举
- javascript - React Native 查找文本是否溢出容器
- python-3.x - 如何在不破坏工作表内容的情况下使用 Python 将 Excel 工作表转换为 PDF?
- python-3.x - Python 日志记录:自定义记录器没有输出
- c# - 使用 C# 的 Visual Studio Exchange 命令行管理程序 Add-ContentFilterPhrase cmdlet
- javascript - 使用文本框自定义多选 - 使用 contenteditable
- r - 将下拉按钮链接到闪亮的数据
- javascript - Zapier 中的 JavaScript 使用分页循环 API 调用
- python - 操作 Pandas 数据框的数据