Better pagination for account > orders

This commit is contained in:
Claudio Sanches 2016-01-20 13:46:59 -02:00
parent 36c0b6047a
commit d193caa987
5 changed files with 19 additions and 14 deletions

View File

@ -94,8 +94,8 @@ class WC_Query {
$title = __( 'Order Received', 'woocommerce' );
break;
case 'orders' :
if ( isset( $_GET['orders-page'] ) ) {
$title = sprintf( __( 'Orders (page %d)', 'woocommerce' ), intval( $_GET['orders-page'] ) );
if ( ! empty( $wp->query_vars['orders'] ) ) {
$title = sprintf( __( 'Orders (page %d)', 'woocommerce' ), intval( $wp->query_vars['orders'] ) );
} else {
$title = __( 'Orders', 'woocommerce' );
}

View File

@ -107,9 +107,11 @@ function wc_get_account_orders_columns() {
/**
* Get My Account > Orders query args.
*
* @since 2.6.0
* @param int $current_page
* @return array
*/
function wc_get_account_orders_query_args() {
function wc_get_account_orders_query_args( $current_page = 1 ) {
$args = array(
'numberposts' => 2,
'meta_key' => '_customer_user',
@ -125,8 +127,8 @@ function wc_get_account_orders_query_args() {
$args['posts_per_page'] = $args['numberposts'];
unset( $args['numberposts'] );
if ( isset( $_GET['orders-page'] ) && 1 < $_GET['orders-page'] ) {
$args['paged'] = absint( $_GET['orders-page'] );
if ( 1 < $current_page ) {
$args['paged'] = absint( $current_page );
}
return apply_filters( 'woocommerce_account_orders_query', $args );

View File

@ -2029,9 +2029,13 @@ if ( ! function_exists( 'woocommerce_account_orders' ) ) {
/**
* My Account > Orders template.
*
* @param int $current_page Current page number.
*/
function woocommerce_account_orders() {
wc_get_template( 'myaccount/orders.php' );
function woocommerce_account_orders( $current_page ) {
$current_page = empty( $current_page ) ? 1 : $current_page;
wc_get_template( 'myaccount/orders.php', array( 'current_page' => absint( $current_page ) ) );
}
}

View File

@ -51,7 +51,7 @@ $col = 1;
<div class="col-<?php echo ( ( $col = $col * -1 ) < 0 ) ? 1 : 2; ?> address">
<header class="title">
<h3><?php echo $title; ?></h3>
<a href="<?php echo wc_get_endpoint_url( 'edit-address', $name ); ?>" class="edit"><?php _e( 'Edit', 'woocommerce' ); ?></a>
<a href="<?php echo esc_url( wc_get_endpoint_url( 'edit-address', $name ) ); ?>" class="edit"><?php _e( 'Edit', 'woocommerce' ); ?></a>
</header>
<address>
<?php

View File

@ -21,8 +21,7 @@ if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$customer_orders = new WP_Query( wc_get_account_orders_query_args() );
$current_page = isset( $_GET['orders-page'] ) ? absint( $_GET['orders-page'] ) : 1;
$customer_orders = new WP_Query( wc_get_account_orders_query_args( $current_page ) );
wc_get_template( 'myaccount/navigation.php' ); ?>
@ -104,11 +103,11 @@ wc_get_template( 'myaccount/navigation.php' ); ?>
<?php if ( 1 < $customer_orders->max_num_pages ) : ?>
<div class="wc-account-orders-pagination">
<?php if ( 1 !== $current_page ) : ?>
<a class="button" href="<?php echo esc_url( add_query_arg( array( 'orders-page' => $current_page - 1 ) ) ); ?>"><?php _e( 'Previous', 'woocommerce' ); ?></a>
<a class="button" href="<?php echo esc_url( wc_get_endpoint_url( 'orders', $current_page - 1 ) ); ?>"><?php _e( 'Previous', 'woocommerce' ); ?></a>
<?php endif; ?>
<?php if ( $current_page !== intval( $customer_orders->max_num_pages ) ) : ?>
<a class="button" href="<?php echo esc_url( add_query_arg( array( 'orders-page' => $current_page + 1 ) ) ); ?>"><?php _e( 'Next', 'woocommerce' ); ?></a>
<a class="button" href="<?php echo esc_url( wc_get_endpoint_url( 'orders', $current_page + 1 ) ); ?>"><?php _e( 'Next', 'woocommerce' ); ?></a>
<?php endif; ?>
</div>
<?php endif; ?>