WooCommerce Grid / List view

Is there any experience with Woocommerce Grid / List view plugin, I set to automatically start the list view but the problem is that while the page is loading initially opens a grid view and instantly change to list view, it takes 1 second but it seems confusing.Is there any idea how it could be resolved?

I took the code from the following link

jQuery(document).ready(function(){
    jQuery('ul.products').addClass('list');
});

Related posts

Leave a Reply

1 comment

  1. Undo any changes you’ve have made to the file, then add this at the top:

    if ( jQuery.cookie( "gridcookie" ) != "grid" ) {
        jQuery.cookie( "gridcookie", "list", { path: "/" } );
    } 
    

    Update: Sounds like a FOUC. Let’s take a different approach – remove the code you added above & try adding the following to your theme’s functions.php:

    add_action( 'woocommerce_after_shop_loop', 'wpse_71885_shop_loop_list_init' );
    
    function wpse_71885_shop_loop_list_init() {
        ?>
    
    <script type="text/javascript">
        jQuery( "ul.products" ).addClass( jQuery.cookie( "gridcookie" ) || "list" );
    </script>
    
    <?php
    }
    

    This will add the grid/list class to the product list immediately after it enters the document (as opposed to waiting for document ready).