Okay
  Public Ticket #1302821
Product Gallery thumb-prev and thumb-next does not appent after ajax load new woocommerce products
Closed

Comments

  •  1
    Mfboutique started the conversation

    This is code from your theme - wp-content/themes/oxygen/assets/js/oxygen-custom.js   The issue that I am having is not caused by the plugin, but depends on the theme that I using.

    The code I sent is not working because it is processed only on document ready,, which means, only when the page is loaded. There's no way to process that code snippet again after an AJAX call and the plugin cannot change this behaviour either. I need solution for this issue please. Do you understand what is my issue? Thank you 

    Line 316 

    // Product Gallery (Loop) $(".product .full-gallery").each(function(i, el) { var $this = $( el ).parents( '.product' ), $images = $this.find('.image.full-gallery .thumb img');

    if($images.length > 1) { $this.find('.image').append( '<a href="#" class="thumb-prev">Prev</a><a href="#" class="thumb-next">Next</a>' );

    var $nextprev = $this.find('.thumb-prev, .thumb-next');

    $nextprev.on('click', function(ev) { ev.preventDefault();

    var dir = $(this).hasClass('thumb-prev') ? -1 : 1, $curr = $images.filter(':not(.hidden-slowly)'), $next = $curr.next();

    if(dir == 1) { if($next.length == 0) $next = $images.first(); } else { $next = $curr.prev();

    if($next.length == 0) $next = $images.last(); }

    $next.addClass('enter-in notrans ' + (dir == -1 ? 'ei-left' : '')).removeClass('hidden hidden-slowly hs-left hs-right'); $curr.addClass('hidden-slowly ' + (dir == -1 ? 'hs-left' : ''));

    setTimeout(function(){ $next.removeClass('enter-in notrans ei-left'); }, 0); }); } });

  • [deleted] replied

    Hi,

    Can you please let me know what code snippet you are trying to implement. I am not able to access your site to see the problem there, it is showing me this message:

    Access denied. You need to Login first

  •  1
    Mfboutique replied

    Hi Arlind, 

    you can access and see issue here - 

    https://miamifashionboutique.com/mfbstage/?product_cat=booties

    user: mmijatovic
    pass: u3JOsajuAvU#SU#fi)dle3jh

    I have this issue: 1. Open wp-content/themes/oxygen/inc/laborator_woocommerce.php 2. Find function oxygen_woocommerce_loop_item_thumbnail() { – Line 698 3. Open wp-content/themes/oxygen/assets/js/oxygen-custom.js – Line 316 4. Find $(”.product .full-gallery”).each(function(i, el)

    I want to include $(”.product .full-gallery”).each(function(i, el) in function oxygen_woocommerce_loop_item_thumbnail() { ... so when Yith infinite scroll load new woocommerce products, product should have thumb-prev and thumb-next, your function execute only on document.ready now. Do you understand my question ?

    You will see that we dont have thumb-prev and thumb-next on the new loaded woocommerce products. Thank you

  • [deleted] replied

    Hi,

    I've analyzed how YITH infinite scroll works and I have created this code for you (already added in Theme Options > Footer > JavaScript):

    <script>
    jQuery( document ).on( 'yith_infs_added_elem', function( e, elem, current_url ) {

    jQuery( elem ).each( function( i, el ) {
    var $this = jQuery( el ),
    $images = $this.find('.image.full-gallery .thumb img');

    if($images.length > 1)
    {
    $this.find('.image').append( '<a href="#" class="thumb-prev">Prev</a><a href="#" class="thumb-next">Next</a>' );

    var $nextprev = $this.find('.thumb-prev, .thumb-next');

    $nextprev.on('click', function(ev)
    {
    ev.preventDefault();

    var dir = jQuery(this).hasClass('thumb-prev') ? -1 : 1,
    $curr = $images.filter(':not(.hidden-slowly)'),
    $next = $curr.next();

    if(dir == 1)
    {
    if($next.length == 0)
    $next = $images.first();
    }
    else
    {
    $next = $curr.prev();

    if($next.length == 0)
    $next = $images.last();
    }

    $next.addClass('enter-in notrans ' + (dir == -1 ? 'ei-left' : '')).removeClass('hidden hidden-slowly hs-left hs-right');
    $curr.addClass('hidden-slowly ' + (dir == -1 ? 'hs-left' : ''));

    setTimeout(function(){ $next.removeClass('enter-in notrans ei-left'); }, 0);
    });
    }
    } );

    } );
    </script>

    So now the new items that are loaded from YITH are processed and gallery works fine.

  •  1
    Mfboutique replied

    Thank you Arlind for your help,


    that's exactly what we want :)

  • [deleted] replied

    Hi Mfboutique,

    I'm glad to hear that buddy

    Sorry for the delay of your ticket.

    P.S: If you like our theme, it would help us a lot if you could give us five star rating on themeforest from your Downloads tab.

    A huge thank you from Laborator in advance and have an amazing week!

  •  1
    Mfboutique replied

    Just one more question what I noticed, see here - http://prntscr.com/gmmquh

    This is issue because new loaded products does not have <div class="clear"></div> after every 4 product in row. 

    Products which is loaded on document ready has <div class="clear"> after every fourth product. Can you help me how to fix this issue? Thank you

    wp-content/themes/oxygen/inc/laborator_functions.php 

    Line 96 - <div class="clear"></div> 

    How to append this line of code after every fourth product in my case. Thank you

  • [deleted] replied

    Hi again,

    I have corrected the code I have sent you previously to this one:

    <script>
    jQuery( document ).on( 'yith_infs_adding_elem', function( e, elem, current_url ) {
    var productsShown = jQuery( '.items .row > .product' ).length;

    jQuery( elem ).each( function( i, el ) {
    var $this = jQuery( el ),
    $images = $this.find('.image.full-gallery .thumb img');

    if ( ( productsShown + i ) % 4 == 0 ) {
    //$this.before( '<div class="clear"></div>' );
    $this.css( {
    clear: 'left'
    } );
    }

    if($images.length > 1)
    {
    $this.find('.image').append( '<a href="#" class="thumb-prev">Prev</a><a href="#" class="thumb-next">Next</a>' );

    var $nextprev = $this.find('.thumb-prev, .thumb-next');

    $nextprev.on('click', function(ev)
    {
    ev.preventDefault();

    var dir = jQuery(this).hasClass('thumb-prev') ? -1 : 1,
    $curr = $images.filter(':not(.hidden-slowly)'),
    $next = $curr.next();

    if(dir == 1)
    {
    if($next.length == 0)
    $next = $images.first();
    }
    else
    {
    $next = $curr.prev();

    if($next.length == 0)
    $next = $images.last();
    }

    $next.addClass('enter-in notrans ' + (dir == -1 ? 'ei-left' : '')).removeClass('hidden hidden-slowly hs-left hs-right');
    $curr.addClass('hidden-slowly ' + (dir == -1 ? 'hs-left' : ''));

    setTimeout(function(){ $next.removeClass('enter-in notrans ei-left'); }, 0);
    });
    }
    } );

    } );
    </script>

    The products are now aligned properly in rows.