WooCommerce:如何显示属性变化描述 [英] WooCommerce: How to show attribute variation description

查看:180
本文介绍了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>

推荐答案

请参见 term_description()

类似如下的内容应创建带有其描述的术语列表:

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.

这篇关于WooCommerce:如何显示属性变化描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆