php - 如何从 WooCommerce 产品属性术语中获取元数据
问题描述
特定属性列表的 meta_value 包含图像的名称。有没有办法可以访问属性的 meta_values 列表?这给了我所有的名字,但我也需要 meta_values:
global $product;
$stain=$product->get_attribute('pa_stain-color');
echo $stain;
我怎样才能得到 meta_values?我已经尝试了许多变体,但根本无法获得 meta_values。
解决方案
由于每个产品属性都是自定义 WooCommerce 产品分类法,因此对于特定的自定义分类法,您可以获取附加到产品的术语,然后获取术语元数据,如下所示:
$taxonomy = 'pa_stain-color';
$terms = wp_get_post_terms( get_the_ID(), $taxonomy ); // Get terms for the product
if ( ! empty($terms) ) {
foreach ( $terms as $term ) {
$meta_data = get_term_meta( $term->term_id ); // Get all meta data
// Display the term name
echo '<p>' . $term->name . '</p>';
// Raw array output from term meta data
echo '<pre>' . print_r($meta_data, true) . '</pre>';
}
}
推荐阅读
- python - 将日期格式解析为日期时间
- azure - Azure 信息保护 | 如何解密来自 EWS API 的 .EML?
- python-3.x - 将字符串 (f. E. 6,6) 更改为浮动
- javascript - 在选择中搜索数据
- javascript - 为什么点击后 daterangepicker 不显示?
- python - 在 jenkins 中运行 Python 脚本
- javascript - 如何将初始化的 selectizejs 输入字段放入 sweetalert
- powershell - 将 Powershell 变量传递到命令提示符行
- python - 从.txt文件读取时如何检查两个字符串是否在同一行
- xamarin.ios - 在应用程序加载器中发布 Xamarin.iOS IPA 时出错