WooCommerce:如何显示属性变化描述
在WooCommerce的产品">属性">"[属性名称]">添加新的[属性变体]"下,有一个标题为描述"的部分,文字为描述在默认情况下不突出;但是,某些主题可能会显示它. "
In WooCommerce under Products > Attributes > [Name of Attribute] > Add New [Attribute Variation] there is a section titled "Description" with the text "The description is not prominent by default; however, some themes may show it."
我想在附加信息"选项卡中的属性变体下方的主题中显示它.这是我目前在那里的代码.我希望您能获得关于如何使属性变化描述显示在属性变化下方的任何建议.
I'd like to show it in my theme directly below the attribute variation in the Additional Information tab. this is the code I currently have there. I'd appreciate any advice on how to get the attribute variation description to show just below the attribute variation.
<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>
类似如下的内容应创建带有其描述的术语列表:
Something like the following should create a list of terms with their descriptions:
$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>';
}
或者,如果您不希望描述通过WordPress的默认过滤器运行,您应该只能使用$term->description
.
Or if you don't want the description running through WordPress' default filters you should be able to just use $term->description
.