• Resolved palomar83

    (@palomar83)


    Hello Florian,

    I noticed that the woocommerce product images on my website are not lazyloaded. See here: https://hautlescours.fr/produit/olivier-regin/ for the image at the top.

    Though they have a “wp-post-image” class and data-src attribute. I must admit I don’t know how my theme handles those images.

    Thanks for your help,

    Nicolas

    If this helps here is some code I had added to my functions.php when I created the website 3 years ago, following the adivce on a blog, but I am not sure how useful it is:

    
    //this line removes the existing Woocommerce codes
    remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
    
    remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
    
    //This line adds a new action which adds a tag BEFORE the woocommerce "stuff"
    
    add_action('woocommerce_before_main_content', 'my_theme_wrapper_start', 10);
    
    //This line adds a new action which adds a tag AFTER the woocommerce "stuff"
    
    add_action('woocommerce_after_main_content', 'my_theme_wrapper_end', 10);
    
    //This line adds a new css section tag called "woogrid" BEFORE the woocommerce "stuff"
    
    function my_theme_wrapper_start() { echo '<section id="woogrid">'; }
    
    //This line ends the new "woogrid" section
    
    function my_theme_wrapper_end() { echo '</section>'; }
    
    /****Afficher la taille des images dans la librairie de WordPress**/
    add_filter('manage_upload_columns', 'size_column_register');
    
    function size_column_register($columns) {
    
        $columns['dimensions'] = 'Dimensions';
    
        return $columns;
    }
    
    add_action( 'after_setup_theme', 'woocommerce_support' );
    function woocommerce_support() {
        add_theme_support( 'woocommerce' );
    }
    
    add_action('manage_media_custom_column', 'size_column_display', 10, 2);
    
    function size_column_display($column_name, $post_id) {
    
        if( 'dimensions' != $column_name || !wp_attachment_is_image($post_id))
            return;
    
        list($url, $width, $height) = wp_get_attachment_image_src($post_id, 'full');
    
        echo esc_html("{$width}&times;{$height}");
    }
    
    // Change number or products per row to 2 in Woocommerce
    add_filter('loop_shop_columns', 'loop_columns');
    if (!function_exists('loop_columns')) {
    	function loop_columns() {
    		return 2; // 2 products per row
    	}
    }
    
    // Display 24 products per page. Goes in functions.php
    /*add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 4;' ), 20 );*/
    
    /**
     * Change number of products that are displayed per page (shop page)
     */
    add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 );
    
    function new_loop_shop_per_page( $cols ) {
      // $cols contains the current number of products per page based on the value stored on Options -> Reading
      // Return the number of products you wanna show per page.
      $cols = 12;
      return $cols;
    }
    
    //Les mininatures d'un produit Woocommerce font 200x200
    add_filter( 'woocommerce_get_image_size_gallery_thumbnail', function( $size ) {
    return array(
    'width' => 200,
    'height' => 200,
    'crop' => 0,
    );
    } );
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Florian Brinkmann

    (@florianbrinkmann)

    Hi Nicolas,

    thanks for opening the issue. The image is displayed with a filter that is not supported in the current Lazy Loader release. Instead of adding it for all users in a new version, I added a textarea in the settings where you can add filters that should be processed by Lazy Loader. For the WooCommerce image, the filter woocommerce_single_product_image_thumbnail_html should be the right one.

    In addition, I added a option to process the complete markup of the page, instead of only parts of it via the filters. This might lead to unwanted behavior, when the page contains HTML errors, because the DOM Parser tries to correct them.

    Would you give one of the options a try in the latest beta version (https://github.com/florianbrinkmann/lazy-loading-responsive-images/releases/tag/v6.0.0-beta.1 it is the lazy-loading-responsive-images.zip) and check if it works for you?

    Thanks,
    Florian

    Plugin Author Florian Brinkmann

    (@florianbrinkmann)

    For the record: After email conversation I found the issue: the WooCommerce image gets a data-src attribute and is therefore skipped by Lazy Loader to prevent conficts with other lazy loading functions. So, it is not possible to lazy load the image currently. Only way would be to overwrite the WC template and create the image markup without data-src.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Woocommerce product images not lazyloaded’ is closed to new replies.