• Resolved simooo

    (@simooo)


    Hi there! I have an issue with WooCommerce thumbnails in the following two cases that don’t seem to respect the thumbnail size I’ve configured.

    Case 1: images displayed by the Gutenberg product category block
    Case 2: using $_product->get_image(‘thumbnail’) within a hook

    I’m using the following code to increase the thumbnail size to 300 pixels instead of 150 pixels but this doesn’t seem to take effect. Is there something missing here to override the default thumbnail size?

    function redefine_woocommerce_thumbnail_size() {
    add_image_size( ‘woocommerce_thumbnail’, 300, 300, true );
    }
    add_action( ‘after_setup_theme’, ‘redefine_woocommerce_thumbnail_size’ );

    add_theme_support( ‘woocommerce’, array(
    ‘thumbnail_image_width’ => 300,
    ) );

    In the customizer, images are set as “uncropped”.

    The images appear with a full source set including high res sources. But the sizes attribute looks like this:
    sizes=”(max-width: 150px) 100vw, 150px”

    This means the higher res versions are available but are ignored by the browser and the low resolution version is displayed instead. If I manually remove the sizes attribute the images are displayed correctly.

    I’ve tried regenerating thumbnails from the WooCommerce settings, but as mentioned above the issue doesn’t seem to be with the files but rather with the markup and the sizes attribute.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support nicw.a11n

    (@nicw)

    Hi @simooo

    Have you tried the following when fetching your thumbnail?

    $product->get_image( 'woocommerce_thumbnail' );

    The Product Category Block gets it’s image The image is produced by the woocommerce_subcategory_thumbnail() function. This sets the size of the image using the filter
    subcategory_archive_thumbnail_size. The default is woocommerce_thumbnail

    Generally, it seems that your woocommerce_thumbnail is set to 150px somewhere by a theme or plugin.

    There is a $dimensions variable which is used when checking sizes.

    $dimensions = wc_get_image_size( 'woocommerce_thumbnail' );

    This returns an array. The height value of this variable is empty when printed:

    Array (
        [width] => 150
        [height] => 
        [crop] => 0
    )
    

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Thread Starter simooo

    (@simooo)

    Hi @nicw !

    Thanks so much for your detailed reply.

    I just tried printing out wc_get_image_size('woocommerce_thumbnail') as you suggested. It returns with 300!

    Array ( [width] => 300 [height] => [crop] => 0 )

    I’m doing this at the top of my file which deals with hooks and filters, i.e. before I’m running add_image_size etc. What this suggests to me is that my settings were preserved since the last request and are in fact not being overridden elsewhere.

    I also tried specifying woocommerce_thumbnail instead of just thumbnail in $_product->get_image('woocommerce_thumbnail') as you suggested, which makes a lot of sense. But it still spits out an image with max-width: 150.

    Finally, I tried adding the filter you suggested – hope I got this right?

    // Try to override category thumb size
    function size_of_category_thumb($u) {
    return array(300, 300, true);
    }
    add_filter('subcategory_archive_thumbnail_size', 'size_of_category_thumb');

    Unfortunately this doesn’t seem to make a difference either: the thumbnails in the category block grid also still have a max-width: 150 like before. I have shift + refreshed so many times!

    It’s slightly maddening!

    Plugin Support Douglas I. a11n

    (@imodouglas)

    Hi @simooo,

    I am sorry to hear that this keeps happening. Can you share the link to a page where these thumbnails are displayed so we can see if this can be overridden using CSS?

    Thread Starter simooo

    (@simooo)

    Hi @imodouglas !

    The problematic pages are lasala.art and lasala.art/gallery. But I now have a workaround in place, which uses Javascript and replaces both the sizes attribute and also the data-sizes attribute, since both of these had a max-size of 150px set. I’m replacing them with identical attributes just changing 150 to 300. So I’m not sure if you will be able to see the issue.

    Interestintly, replacing only sizes wasn’t enough, I needed to also replace data-sizes. I guess there is some script in place copying from the latter to the form.

    Plugin Support Douglas I. a11n

    (@imodouglas)

    Hi @simooo,

    Thank you for sharing the link with us. Just as you said, I was not able to see the issue but I am happy to hear that you found a workaround for this issue.

    Can you confirm that this is sorted for now?

    Thread Starter simooo

    (@simooo)

    Definitely a very hacky workaround and the basic problem remains: the wrong size is being assigned. But yes, personally I’m no longer in need of a solution.

    Plugin Support Douglas I. a11n

    (@imodouglas)

    Hi @simooo,

    I completely understand. Since this is something that I cannot replicate on my end, there is a possibility that it could be something caused by your theme or a plugin on your site.

    Since we do not have access to test further and you have a workaround that works, I think this is good for now.

    I would go ahead and mark this thread as solved. If the issue comes up again, it would be best to do a full conflict test to see find where the issue is coming from.

    All the best! ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Thumbnail sizes not reflected correctly’ is closed to new replies.