• Resolved mimiseku93002

    (@mimiseku93002)


    Hello,

    I’m trying to add the terms of 2 custom taxonomies to the product loop, just under the title and above the price so I added this code to function.php of my child theme.

    function product_loop_meta() {
        $terms_artist = get_the_terms( $post->ID , 'artist' ); 
                        foreach ( $terms_artist as $term_artist ) {
                            $term_link_artist = get_term_link( $term_artist, 'artist' );
                            if( is_wp_error( $term_link_artist ) )
                            continue;
    		     }
        $terms_label = get_the_terms( $post->ID , 'label' ); 
                        foreach ( $terms_label as $term_label ) {
                            $term_link_label = get_term_link( $term_label, 'label' );
                            if( is_wp_error( $term_link_label ) )
                            continue;
                        }
        echo 
                        '<div class="product-loop-meta">
                                <a href="' . $term_link_artist . '">' . $term_artist->name. ' </a><br>
                                <a href="' . $term_link_label . '">' . $term_label->name. ' </a>
                        </div>';
    
    }
    
    add_action('woocommerce_shop_loop_item_title','product_loop_meta',15);

    But it’s not working. Any idea to fix that?
    Thanks

    • This topic was modified 2 years, 4 months ago by mimiseku93002.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @mimiseku93002

    Thanks for reaching out!

    Firstly, I apologized for the delayed response.

    I added your code to my personal site, however, I received an error as well.

    Can you please share with us your site goals or what are you trying to achieve on your site so that we could address you more effectively?

    If a screenshot would be helpful, I’d recommend using https://snipboard.io or https://skitch.com/. You can share the direct link to the image as a response to this topic.

    Thread Starter mimiseku93002

    (@mimiseku93002)

    Hello @xue28

    No worries thanks for your reply, here’s how I’d like to have the product displayed.

    https://snipboard.io/IomPr7.jpg

    Thanks

    Thread Starter mimiseku93002

    (@mimiseku93002)

    Hey,

    I actually managed to get this result by customing the woocommerce_template_loop_product_title like this

    function woocommerce_template_loop_product_title() {
    
    		$terms_artist = get_the_terms( $post->ID , 'artist' ); 
    	foreach ( $terms_artist as $term_artist ) {
    		$term_link_artist = get_term_link( $term_artist, 'artist' );
    		if( is_wp_error( $term_link_artist ) )
    		continue;
    	}
    	$terms_label = get_the_terms( $post->ID , 'label' ); 
    	foreach ( $terms_label as $term_label ) {
    		$term_link_label = get_term_link( $term_label, 'label' );
    		if( is_wp_error( $term_link_label ) )
    		continue;
    	} 
    		echo '<h2 class="' . esc_attr( apply_filters( 'woocommerce_product_loop_title_classes', 'woocommerce-loop-product__title' ) ) . '">' . get_the_title() . '</h2>
    		<p class="' . esc_attr( apply_filters( 'woocommerce_product_loop_title_classes', 'woocommerce-loop-product__title' ) ) . '"><a href="' . $term_link_artist . '">' . $term_artist->name. ' </a><br>
    		<a href="' . $term_link_label . '">' . $term_label->name. ' </a></p>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    	}
    }

    But I’d like to have this change in my child theme so it won’t be overide with the next Woocommerce Update. Any ideas?

    Hi @mimiseku93002

    I actually managed to get this result by customing the woocommerce_template_loop_product_title like this

    I’m glad you were able to find a solution to your inquiry here and thanks for sharing it with the community too! ??

    But I’d like to have this change in my child theme so it won’t be overide with the next Woocommerce Update. Any ideas?

    I recommend using the Code Snippets plugin to add code to your site or you can check this article about How to Properly Add WooCommerce Custom Code for your reference.

    Hope this helps!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add infos to the product loop’ is closed to new replies.