Php 在商业中获取所有产品属性及其术语
我已经研究了一整天,但似乎无法得到一个直接的答案我如何才能得到设置的产品属性以及每个属性的配置条款 这就是我现在拥有的Php 在商业中获取所有产品属性及其术语,php,wordpress,woocommerce,custom-taxonomy,taxonomy-terms,Php,Wordpress,Woocommerce,Custom Taxonomy,Taxonomy Terms,我已经研究了一整天,但似乎无法得到一个直接的答案我如何才能得到设置的产品属性以及每个属性的配置条款 这就是我现在拥有的 //get the terms $attribute_taxonomies = wc_get_attribute_taxonomies(); $taxonomy_terms = array(); if ( $attribute_taxonomies ) { foreach ($attribute_taxonomies as $tax) {
//get the terms
$attribute_taxonomies = wc_get_attribute_taxonomies();
$taxonomy_terms = array();
if ( $attribute_taxonomies ) {
foreach ($attribute_taxonomies as $tax) {
//dont know what to add here
}
}
var_dump($taxonomy_terms);
在下面,您将获得所有产品属性及其各自术语名称的列表:
echo '<ul>';
// Loop through WooCommerce registered product attributes
foreach( wc_get_attribute_taxonomies() as $values ) {
// Get the array of term names for each product attribute
$term_names = get_terms( array('taxonomy' => 'pa_' . $values->attribute_name, 'fields' => 'names' ) );
echo '<li><strong>' . $values->attribute_label . '</strong>: ' . implode(', ', $term_names);
}
echo '</ul>';
这将允许使用foreach循环从每个术语中获取所需的内容…首先使用var\u dump()检查wc\u get\u attribute\u taxonomies()函数
// Get the array of the WP_Terms Object for the each product attribute
$terms = get_terms( array('taxonomy' => 'pa_' . $values->attribute_name );