Php 在电子商务中显示链接的产品属性术语名称

Php 在电子商务中显示链接的产品属性术语名称,php,wordpress,woocommerce,custom-taxonomy,taxonomy-terms,Php,Wordpress,Woocommerce,Custom Taxonomy,Taxonomy Terms,这是我的代码,用于在产品标题下显示一个atributte。如何将其显示为指向此属性存档页的链接 add_action( 'woocommerce_single_product_summary', 'custom_template_single_title', 5 ); function custom_template_single_title() { global $product; $brand_name = $product->get_attribute('Autor

这是我的代码,用于在产品标题下显示一个atributte。如何将其显示为指向此属性存档页的链接

add_action( 'woocommerce_single_product_summary', 'custom_template_single_title', 5 );
function custom_template_single_title() {
    global $product;

    $brand_name = $product->get_attribute('Autor');

    echo '<div class ="author-product">';

    if( $brand_name )
        echo  $brand_name;

    echo '</div>';
}
add_action('woocommerce_single_product_summary','custom_template_single_title',5);
函数自定义模板单个标题(){
全球$产品;
$brand_name=$product->get_属性('Autor');
回声';
如果($品牌名称)
echo$brand_name;
回声';
}

首先,
$product->get_属性('Autor')
可以提供多个术语名

下面,我们向每个术语名称添加术语链接(如果有多个术语名称):

add_action('woocommerce_single_product_summary','custom_template_single_title',5);
函数自定义模板单个标题(){
全球$产品;
$taxonomy='pa_autor';//获取属性($taxonomy)){
//循环浏览术语名称
foreach(分解(“,”,$term\u名称)为$term\u名称){
$term\u id=get\u term\u by('name',$term\u name,$taxonomy)->term\u id;//获取术语id
$term\u link=get\u term\u link($term\u id,$taxonomy);//获取术语链接
$linked_术语[]='';
}
//输出
回显“”。内爆(“,”,$linked_术语)。“”;
}
}

代码进入活动子主题(或活动主题)的functions.php文件。经过测试,工作正常。

工作正常!非常感谢。
add_action( 'woocommerce_single_product_summary', 'custom_template_single_title', 5 );
function custom_template_single_title() {
    global $product;

    $taxonomy     = 'pa_autor'; // <== The product attribute taxonomy
    $linked_terms = []; // Initializing

    if ( $term_names = $product->get_attribute($taxonomy) ) {
        // Loop through the term names
        foreach( explode(', ', $term_names) as $term_name ) {
            $term_id        = get_term_by('name', $term_name, $taxonomy)->term_id; // get the term ID
            $term_link      = get_term_link( $term_id, $taxonomy ); // get the term link

            $linked_terms[] = '<a href="' . $term_link . '">' . $term_name . '</a>';
        }

        // Output
        echo '<div class ="author-product">' . implode(', ', $linked_terms) . '</div>';
    }
}