Reduce Thumbs size of some products in Woocommerce/insert products without shortcode

Asked

Viewed 1,555 times

1

Has a virtual store 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 category B. So at home the Thumbs of category B products have to be smaller than those of category A. I need to reduce them but only know reduce of all.

Doing this without putting your hand in the code I think it’s impossible, no? I haven’t found 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 didn’t work. I wanted to try to insert by code and thus 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 width and height only 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  ?>
  • And how do you reduce all Humbs? How are you differentiating one category from another? Which shortcode are you using? Why is your code only pulling 1 product per page? How are you doing the Output product information?

  • This code was an example that I inserted in the template’s home file that I use to try to call the products in the traditional way with shortcode, where there is 1 could be another value, anyway but it did not work. I was using [product_categories number=""], as I had to put the products in a specific order I am using a by shortcode [product id="2243"] [product id="2240"] [product id="2234"]... To change the size of all is in Tools>Regen. Thumbnails

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 must override the function woocommerce_template_loop_product_thumbnail().

For example if your "Category B" has 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 );
}

Remembering also to change thumbnail by the image size Slug you created.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.