WooCommerce:显示活动属性的描述

时间:2015-12-04 00:44:24

标签: php wordpress woocommerce

WooCommerce允许您编写属性描述,但不会在任何地方显示。

我想在类别页面上显示此属性描述,但仅在选择(pa_color)时仅针对一种类型的属性。

下面的解决方案。希望能节省你一些时间!

1 个答案:

答案 0 :(得分:0)

/*
* If color filter active, show its attribute description on the Archive page
*/
add_action('woocommerce_archive_description', 'custom_attribute_description');

function custom_attribute_description() { 

    global $_chosen_attributes;

    if ( isset($_chosen_attributes['pa_color']) ) {

        $_chosen_color_id = $_chosen_attributes['pa_color']['terms'][0];

        // Prevent non-number IDs from being used
        $_chosen_color_id = preg_replace('/\D/', '', $_chosen_color_id);
        $_chosen_color_details = get_term( $_chosen_color_id, 'pa_color' );

        echo '<div class="chosen-color-description">';
        echo '<strong>' . $_chosen_color_details->name . '</strong>: ';
        echo $_chosen_color_details->description;
        echo '</div>';
    }

}
相关问题