WooCommerce: Showing Descriptions for Active Attribute

WooCommerce lets you write an attribute description, but it doesn't display anywhere.

I was wanting to display this attribute description on the category page, but only for one type of attribute, when it is selected (pa_color).

Solution below. Hopefully saves you some time!

Answers


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

}

Need Your Help

Passwords are in plain text file. How to use them in linux expect script?

linux ssh tcl expect

I want to ssh to remote server using expect script. Passwords are stored in a plain text. I want to send the password reading from the text file. It is working fine in all other cases except where ...