Viewing 17 posts - 1 through 17 (of 17 total)
  • Author
  • #1420102

    In this previous tickets ( Change Shop #3, Change Shop #2, Change Shop), we saw how to display the “Author” attribute (and others) under the woocommerce-product-details__short-description of single product page.

    Now I would like, if possible, that the “Autore” attribute (Author) also appear in the Shop Page and in the products listed in the avia-product-slider-container, under the title.
    As in this image

    Could you please help me?
    Best regards


    Hey Oriano,
    I’m not sure if this is possible, but do you have a staging site with the other modifications active that we can test on?

    Best regards,


    Hi mike,
    yes I have a staging site.
    Find in Private content you account.


    Thanks, I added this code to the end of your child theme functions.php file in Appearance ▸ Editor:

    add_action('woocommerce_after_shop_loop_item_title', 'display_custom_attribute_in_product_grid', 10);
    function display_custom_attribute_in_product_grid(){
        // HERE define the desired product attributes to be displayed
        $defined_attributes = array('autore');
        global $product;
        $attributes = $product->get_attributes();
        if ( ! $attributes ) {
        $out = '<ul class="taste-attributes">';
        foreach ( $attributes as $attribute ) {
            // Get the product attribute slug from the taxonomy
            $attribute_slug = str_replace( 'pa_', '', $attribute->get_name() );
            // skip all non desired product attributes
            if ( ! in_array($attribute_slug, $defined_attributes) ) {
            // skip variations
            if ( $attribute->get_variation() ) {
            $name = $attribute->get_name();
            if ( $attribute->is_taxonomy() ) {
                $terms = wp_get_post_terms( $product->get_id(), $name, 'all' );
                // get the taxonomy
                $tax = $terms[0]->taxonomy;
                // get the tax object
                $tax_object = get_taxonomy($tax);
                // get tax label
                if ( isset ( $tax_object->labels->singular_name ) ) {
                    $tax_label = $tax_object->labels->singular_name;
                } elseif ( isset( $tax_object->label ) ) {
                    $tax_label = $tax_object->label;
                    // Trim label prefix since WC 3.0
                    if ( 0 === strpos( $tax_label, 'Product ' ) ) {
                       $tax_label = substr( $tax_label, 8 );
                $out .= '<li class="' . esc_attr( $name ) . '"style="width:100%" >';
                $out .= '<span class="attribute-label">' . esc_html( $tax_label ) . ': </span> ';
                $tax_terms = array();
                foreach ( $terms as $term ) {
                    $single_term = esc_html( $term->name );
                    array_push( $tax_terms, $single_term );
                $out .= '<span class="attribute-value">' . implode(', ', $tax_terms) . '</span>';
            } else {
                $value_string = implode( ', ', $attribute->get_options() );
                $out .= '<li class="' . sanitize_title($name) . ' ' . sanitize_title( $value_string ) . '">';
                $out .= '<span class="attribute-label">' . $name . ': </span> ';
        $out .= '</ul>';
        echo $out;

    and now the author is showing in the product grid and in the Related products at the bottom of product pages:

    Best regards,


    Hi Mike,
    Would it be possible to eliminate the word “Author”?
    And also, would it be possible to move the author’s name below the title? (Between the title and the price).


    Best regards,


    Hello Mike,
    and, importantly, the link of the author’s name should direct to the author page..
    Example, the link on the author name “Raimondo Maria Pavarin” should open his author page:

    Best regards,


    I have removed the word “Author” and I have moved the name before the price:
    But it can not be a link because the whole element is already a link to the product and you can not have a link inside of a link.

    Best regards,


    Good morning Mike,
    and thanks for your help.

    I presented your solution to the “publishing house” in question, but the director of the publishing house insists on the request to have the author’s name linked to the author page (where all the volumes written by the author appear).
    I told him it’s not possible, but he tells me that he saw a WordPress / WooCommerce site, which has what he’s looking for.
    I asked him for the URL of this site, and he said he will give it to me.
    In case it is of any use, as soon as I have the URL of this site I will write it here.

    Best regards,



    Thank you for the update.

    We modified the display_custom_attribute_in_product_grid function a bit to get the term or autore link and to redirect to the author page, you have to add this script in the functions.php file.

    function av_custom_inline_script()
        // redirect to autore page
        wp_add_inline_script( 'jquery', 
        (function($) {
    	    $(document).ready(function() {
    			$('.products .product a').on('click', function(e) {
    		    	        var link = $(this).attr('href');	
    				if(e.target.className.includes('attribute-value')) link = $(e.target).data('url')
    				window.location.href = link;
    add_action( 'wp_enqueue_scripts', 'av_custom_inline_script' );

    Best regards,


    Hi Ismael,
    I saw that the code “// redirect to autore page” was inserted in the child function, but it doesn’t seem to work, the link assigned to the author’s name always refers to the product and not to the author page :(

    Is there something I’m doing wrong?

    Best regards,


    Hi Ismale, sorry, you’re right, it works now.
    I will do more tests and respond further to update the situation.

    Best regards, and thanks to all Enfold.


    Sorry, maybe you are working on the stage site…
    I’m signing out of my account.


    the director of the “publishing house” gave me the URL of the site that has the solution he was looking for. I put the sati in “private content”.



    Did Ismael’s solution work? I see you wrote that it did but I can’t see it?
    The reason the other site can have a author link below the image is because only the image has the product link, but on your site the whole element has the product link.
    I’m not sure how we can change that without a major element re-write.

    Best regards,


    Hi Mike, sorry for my late reply, to see the stage site, see the info in Private Content.

    The URL below the author’s name indicates the product page, but if you click on the name, you are then redirected to the author’s page.
    It seems to me that it is working correctly now.

    Best regards,


    Ok, so it is working correctly now, shall we close this thread then?

    Best regards,


    Hi Mike
    > Ok, so it is working correctly now, shall we close this thread then?

    Thank you very much.
    Best regards,

Viewing 17 posts - 1 through 17 (of 17 total)
  • The topic ‘Change Shop #4’ is closed to new replies.