Hi – I had a similar problem. WooCommerce uses catalogue images for catalogue and related product images. That is not ideal, for you loose either image quality or speed. So I tried to add a fourth image category for my related products. Howdy McGee has solved the problem. Please take a look at Howdy McGees answer:
Modify Related Product Image Sizes: read his code!
It has worked out magnificently for my needs. For your problem the same logic could be applied. Hope this helps.
Regards,
Theo
**Addition: **
I found a solution that works.
Step 1: Assign a new thumbnail size in your functions.php.
Check reference: wp codex!
/*add your custom size*/
add_action( 'after_setup_theme', 'your_theme_setup' );
function your_theme_setup() {
add_image_size( 'your-thumb', 123, 123, true );//insert your values
}
Note: 'your-thumb', you will use this variable name later
Step 2: Then add the following code wherever you want to display your featured products:
<h1>featured products</h1>
<div class="woocommerce">
<ul class= "products">
<?php
$args = array( 'post_type' => 'product', 'meta_key' => '_featured','posts_per_page' => 4,'columns' => '4', 'meta_value' => 'yes' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<li class="product post-<?php echo get_the_ID(); ?>">
<a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
<?php woocommerce_show_product_sale_flash( $post, $product ); ?>
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'your-thumb'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="123px" height="123px" />'; ?></a>
<h3><?php the_title(); ?></h3><span class="price"><?php echo $product->get_price_html(); ?></span>
</li>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</ul>
</div>
Reference and info:
(www.haloseeker.com/display-woocommerce-featured-products-without-a-shortcode/)
I placed it in the index.php (my homepage) of wootheme mystyle.
Don't forget to use 'your-thumb' on line:
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'your-thumb'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="123px" height="123px" />'; ?></a>
Step 3: Regenerate thumbnails, use the plugin https://wordpress.org/plugins/regenerate-thumbnails/
Step 4: Refresh the browser and inspect the DOM and compare the values
According to your theme you may change the mark up and class names.
I tested the above method and it works well.
The only thing I couldn't do so far, is to add the-add-to-cart-button, because I do not know how to write a variable into the add to cart button shortcode.
This is the code:
<?php echo do_shortcode('[add_to_cart id="variable number?"]'); ?>
I hope this helps.
There is certainly a more elegant way to do this. For instance with a function in the functions.php
Regards,
Theo
_thumbnail_id
-, which should be enough actually,save_post
and similar hooks could be a way to go. But do not forget that those images in your post could be used in other posts as thumbnail, you might want to have a mechanism to account for that.add_filter('intermediate_image_sizes_advanced', '__return_false')
and then resize thumbnail on-the-fly with Glide