これを解決するために私が思いついた関数は次のとおりです。これは、functions.phpファイルに配置する必要があります。使用法については関数のコメントを参照してください...
/**
* This function is used to display a custom image in the shop page if a custom
* image exists for the product. This may be required, for example, to prevent
* images of small products dwarfing images of larger products on the shop page.
*
* To set a custom image for a product, create a custom field for it (in the
* Edit Product page) called custom_product_thumbnail_url . (The image that you
* specify can contain additional white space to prevent it being enlarged.)
*
* This function overrides the function of the same name in WooCommerce's
* woocommerce-template.php file.
*
* @access public
* @subpackage Loop
* @param string $size (default: 'shop_catalog')
* @param int $placeholder_width (default: 0)
* @param int $placeholder_height (default: 0)
* @return string
*/
function woocommerce_get_product_thumbnail( $size = 'shop_catalog', $placeholder_width = 0, $placeholder_height = 0 ) {
global $post, $woocommerce;
if ( ! $placeholder_width )
$placeholder_width = $woocommerce->get_image_size( 'shop_catalog_image_width' );
if ( ! $placeholder_height )
$placeholder_height = $woocommerce->get_image_size( 'shop_catalog_image_height' );
$imgSrc = get_post_meta($post->ID, 'custom_product_thumbnail_url', true);
if ($imgSrc)
return '<img src="'. $imgSrc .'" alt="' . get_the_title($post->ID) . '" width="' . $placeholder_width . '" height="' . $placeholder_height . '" />';
if ( has_post_thumbnail() )
return get_the_post_thumbnail( $post->ID, $size );
elseif ( woocommerce_placeholder_img_src() )
return '<img src="'. woocommerce_placeholder_img_src() .'" alt="Placeholder" width="' . $placeholder_width . '" height="' . $placeholder_height . '" />';
}