gpt4 book ai didi

php - 如何从WooCommerce产品属性分类法的条款?

转载 作者:行者123 更新时间:2023-12-04 08:04:35 27 4
gpt4 key购买 nike

使用以下代码,我通过一个函数(在我的主题的functions.php 中)填充了我添加的管理产品页面中的一个选择下拉项。例如,我设法获得了所有产品属性(分类法)的列表:

<?php               
$attributes = wc_get_attribute_taxonomies();
if($attributes) {
foreach ( $attributes as $attribute ) {
echo '<option value="'. $attribute->attribute_id .'">' . $attribute->attribute_label . '</option>';
}
}
?>
知道如何获取特定产品属性(分类法)下所有术语的术语名称(标签)和 ID,例如 pa_test ?

最佳答案

您可以使用 function get_terms() 获取我们的产品属性分类法的所有术语,如下所示(此处为产品属性 pa_test 分类法):

$taxonomy = 'pa_test';
$terms = get_terms( array('taxonomy' => $taxonomy, 'hide_empty' => false) );

// Loop through the terms for 'pa_test' taxonomy
foreach ( $terms as $term ) {
$term_name = $term->name; // name
$term_slug = $term->slug; // slug
$term_id = $term->term_id; // Id
$term_link = get_term_link( $term ); // Link
}

关于php - 如何从WooCommerce产品属性分类法的条款?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66285142/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com