jeudi 12 février 2015

Wordpress WooCommerce Grid / List toggle: How to trigger a button click?


The "WooCommerce Grid / List toggle"-plugin toggles the view of a list of products in WooCommerce. The last selection is stored in a cookie.


HTML-page contains:



<nav class="gridlist-toggle">
<a href="#" id="grid" title="gridview">&#8862; <span>gridview</span></a>
<a href="#" id="list" title="listview">&#8863; <span>listview</span></a>
</nav>
<ul class="products">
<li class=" ...


Javascript function is:



jQuery(document).ready(function(){

jQuery('#grid').click(function() {
jQuery(this).addClass('active');
jQuery('#list').removeClass('active');
jQuery.cookie('gridcookie','grid', { path: '/' });
jQuery('ul.products').fadeOut(300, function() {
jQuery(this).addClass('grid').removeClass('list').fadeIn(300);
});
return false;
});

jQuery('#list').click(function() {
jQuery(this).addClass('active');
jQuery('#grid').removeClass('active');
jQuery.cookie('gridcookie','list', { path: '/' });
jQuery('ul.products').fadeOut(300, function() {
jQuery(this).removeClass('grid').addClass('list').fadeIn(300);
});
return false;
});

if (jQuery.cookie('gridcookie')) {
jQuery('ul.products, #gridlist-toggle').addClass(jQuery.cookie('gridcookie'));
}

if (jQuery.cookie('gridcookie') == 'grid') {
jQuery('.gridlist-toggle #grid').addClass('active');
jQuery('.gridlist-toggle #list').removeClass('active');
}

if (jQuery.cookie('gridcookie') == 'list') {
jQuery('.gridlist-toggle #list').addClass('active');
jQuery('.gridlist-toggle #grid').removeClass('active');
}

jQuery('#gridlist-toggle a').click(function(event) {
event.preventDefault();
});

});


How do I always get listview on the main shop page and always gridview on category pages disregarding the user's choice?





Aucun commentaire:

Enregistrer un commentaire