繁体   English   中英

WooCommerce:显示活动属性的描述

[英]WooCommerce: Showing Descriptions for Active Attribute

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

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

解决方案如下。 希望可以节省您一些时间!

/*
* 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>';
    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM