首页 文章

WooCommerce:如何显示属性变化描述

提问于
浏览
1

在产品>属性> [属性名称]>添加新[属性变化]下的WooCommerce中,有一个 Headers 为“描述”的部分,文本“默认情况下描述不突出;但是,某些主题可能会显示它” .

我想在“附加信息”选项卡中的属性变体正下方的主题中显示它 . 这是我目前在那里的代码 . 我很感激有关如何让属性变体描述显示在属性变体下方的任何建议 .

<td><?php

  if ( $attribute['is_taxonomy'] ) {

    $values = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' => 'names' ) );
    echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( ', ', $values ) ) ), $attribute, $values );

  } else {

    // Convert pipes to commas and display values
    $values = array_map( 'trim', explode( WC_DELIMITER, $attribute['value'] ) );
    echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( ', ', $values ) ) ), $attribute, $values );
            }
?></td>

1 回答

  • 2

    term_description()

    类似下面的内容应该创建一个带有描述的术语列表:

    $values = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' =>  'all' ) );
    if( $values ){
        echo '<dl>';
            foreach ( $values as $term ){
                echo '<dh>' . $term->name.' </dh>';
                echo '<dd>' . term_description( $term->term_id ) . '</dd>';
            }
        echo '</dl>';
    }
    

    或者如果您没有't want the description running through WordPress'默认过滤器,您应该只能使用 $term->description .

相关问题