Last active
August 8, 2017 16:34
-
-
Save kittenlane/658bac53e45940f63ffc to your computer and use it in GitHub Desktop.
Add 'View All' to WooCommerce pagination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'; | |
} | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' => '←', | |
'next_text' => '→', | |
'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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://raison.co/woocommerce-pagination-view-all/ |
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
Isn't working on WooCommerce 2.6.8 - pagination.php snippet is killing bottom footer widgets areas on Genesis Framework.