Reduce thumbs size of some products in woocommerce / insert products without shortcode

1

There is a virtual shop that displays the products in the home ... products in category A and products in category B. Those in category A are the main ones, those in the secondary B category. So at home the thumbs of the products of category B have to be smaller than those of the category A. I need to reduce them but I only know to reduce of all.

Doing this without putting your hand in the code I think is impossible, right? I did not find any plugin for this.

I tried to use the code below, I inserted it into a page called loop-page in my theme and it did not work. I wanted to try to insert by code and thus to have greater freedom with the html / css of the products. With the shortcode, I was able to organize using float: left, etc, but if I use the width and height it just cuts.

<?php 
$args = array(  
'post_type' => 'product',  
'meta_key' => '_featured',  
'meta_value' => 'yes',  
'posts_per_page' => 1  
);  

$featured_query = new WP_Query( $args );  

if ($featured_query->have_posts()) :   

while ($featured_query->have_posts()) :   

    $featured_query->the_post();  

    $product = get_product( $featured_query->post->ID );  

    // Output product information here  

   endwhile;  

endif;  

wp_reset_query(); // Remember to reset  ?>
    
asked by anonymous 18.07.2014 / 13:10

1 answer

1

First of all you need to set the size of the different thumbnail you want, in case you should use add_image_size() to do this.

Then you should overwrite the woocommerce_template_loop_product_thumbnail() function.

For example if your "Category B" has the slug as music you can do so:

function woocommerce_template_loop_product_thumbnail() {
    global $post;

    $size = 'shop_catalog';

    if ( is_object_in_term( $post->ID, 'product_cat', 'music' ) ) {
        $size = 'thumbnail';
    }

    echo woocommerce_get_product_thumbnail( $size );
}

Also remember to swap thumbnail for the slug of the image size you created.

Finally you should upload the image again or use the Regenerate Thumbnails to recreate all the images.

    
03.08.2014 / 04:27