Skip to content

Instantly share code, notes, and snippets.

@kittenlane
Last active August 8, 2017 16:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kittenlane/658bac53e45940f63ffc to your computer and use it in GitHub Desktop.
Save kittenlane/658bac53e45940f63ffc to your computer and use it in GitHub Desktop.
Add 'View All' to WooCommerce pagination
<?php /* Add to functions.php */
// If using Canvas: Replace WooCanvas Default Pagination with WooCommerce Pagination
add_action('init','alter_woo_hooks');
function alter_woo_hooks() {
remove_action( 'woocommerce_after_main_content', 'canvas_commerce_pagination', 01, 0 );
}
add_action( 'woocommerce_pagination', 'woocommerce_pagination', 1 );
add_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 1 );
// View All - Change No. Products to display
add_filter('loop_shop_per_page', 'wg_view_all_products', 20);
function wg_view_all_products($cols){
if($_GET['view'] === 'all'){
return '999';
}
else {
return '9';
}
}
?>
<?php /* Add to themes/[theme]/woocommerce/loop/pagination.php */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
global $wp_query;
if( $_GET['view'] === 'all' ) { ?>
<div class="woo-pagination wg-view-less"><a href=".">View Less</a></div>
<?php }
if ( $wp_query->max_num_pages <= 1 )
return;
?>
<nav class="woocommerce-pagination woo-pagination">
<?php
echo paginate_links( apply_filters( 'woocommerce_pagination_args', array(
'base' => str_replace( 999999999, '%#%', get_pagenum_link( 999999999 ) ),
'format' => '',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'prev_text' => '&larr;',
'next_text' => '&rarr;',
'type' => 'list',
'end_size' => 3,
'mid_size' => 3
) ) );
?>
<?php if (is_paged()) : ?>
<div class="button wg-view-all wg-view-right"><a href="../../?view=all">View All</a></div>
<?php else: ?>
<div class="wg-view-all wg-view-right"><a href="?view=all">View All</a></div>
<?php endif; ?>
</nav>
http://raison.co/woocommerce-pagination-view-all/
@bisonbrah
Copy link

Isn't working on WooCommerce 2.6.8 - pagination.php snippet is killing bottom footer widgets areas on Genesis Framework.

@makeonlineshop
Copy link

Hello, any update on this ? An easy solution working or latest Woocommerce ? Thank you for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment