Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1215674

    Hello!

    I’m looking for solution to show attribute (taxonomy) inside Masonry Products.

    It’s difficult to find because with this topic (in this forum) it always is suggested to h_ire a d_eveloper.
    At the end, I think that I found a solution that works for me, and can share for others users.


    Show Brand name in Masonry Product,
    add this code in ChildTheme’s “functions.php” file:

    /* ADD BRAND on MASONRY SHOP */
    add_filter( 'avf_masonry_loop_prepare', 'avf_masonry_brand', 10, 2 );
    function avf_masonry_brand( $key, $entries ) {      
    	$id = $key['ID']; 
    	if($key['post_type'] == 'product') {
    		 $brands = wp_get_object_terms( $id, 'pwb-brand', array( 'fields' => 'names' ) );
    		 foreach( $brands as $brand ){	 
    			$output .= '<h6 class="brand" title="BRAND">'. $brand .'</h6>';
    		 }
    	}
        $key['text_after'] .= trim( $output );
        return $key;
    }

    Please, can you tell me if is possible to show under prodcut title, over price?
    (now appears under price)

    Thanks in advance.
    Best Regards!

    • This topic was modified 4 years, 6 months ago by abeldb.
    #1217022

    Hey abeldb,

    Thank you for the inquiry.

    Try to append the output to the the_title key — find this line..

    $key['text_after'] .= trim( $output );
    

    .., then replace it with:

    $key['the_title '] .= trim( $output );
    

    Let us know if that helps.

    Best regards,
    Ismael

    #1217095

    Wow, perfect!
    Thank you very much!!


    Ummm, for future users, take care, extra space after tittle must be deleted
    $key['the_title'] .= trim( $output );

    #1217148

    Hi,

    Did you need additional help with this topic or shall we close?

    Best regards,
    Jordan Shannon

    #1217285

    Hi Jordan!

    Sorry, yes allright!!

    Best regards,


    For other users,
    code to show tax category on masonry products:
    (add on ChidTheme functions.php file)

    
    /* SHOW PRODUCT CAT on MASONRY  */
    add_filter( 'avf_masonry_loop_prepare', 'avf_masonry_cat', 10, 2 );
    function avf_masonry_cat( $key, $entries ) {      
    	$id = $key['ID']; 
    	if($key['post_type'] == 'product') {
    		 $cats = wp_get_object_terms( $id, 'product_cat', array( 'fields' => 'names' ) );
    		 foreach( $cats as $cat ){
    			$output .=  $cat .' &nbsp;'; 		 
    		 }
    	}
        $key['the_title'] .= trim( '<h6 class="cat">'. $output .'</h6>');
        return $key;
    }
    
    #1217486

    Hi,

    Thank you for sharing the solution! If you need help with anything else, please let us know here in the forums.

    Best regards,
    Jordan Shannon

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Masonry Products show attribute (tax) Brand’ is closed to new replies.