Better pagination for account > orders

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

View File

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

View File

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

View File

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

View File

@ -23,13 +23,13 @@ $customer_id = get_current_user_id();
if ( ! wc_ship_to_billing_address_only() && get_option( 'woocommerce_calc_shipping' ) !== 'no' ) { if ( ! wc_ship_to_billing_address_only() && get_option( 'woocommerce_calc_shipping' ) !== 'no' ) {
$page_title = apply_filters( 'woocommerce_my_account_my_address_title', __( 'My Addresses', 'woocommerce' ) ); $page_title = apply_filters( 'woocommerce_my_account_my_address_title', __( 'My Addresses', 'woocommerce' ) );
$get_addresses = apply_filters( 'woocommerce_my_account_get_addresses', array( $get_addresses = apply_filters( 'woocommerce_my_account_get_addresses', array(
'billing' => __( 'Billing Address', 'woocommerce' ), 'billing' => __( 'Billing Address', 'woocommerce' ),
'shipping' => __( 'Shipping Address', 'woocommerce' ) 'shipping' => __( 'Shipping Address', 'woocommerce' )
), $customer_id ); ), $customer_id );
} else { } else {
$page_title = apply_filters( 'woocommerce_my_account_my_address_title', __( 'My Address', 'woocommerce' ) ); $page_title = apply_filters( 'woocommerce_my_account_my_address_title', __( 'My Address', 'woocommerce' ) );
$get_addresses = apply_filters( 'woocommerce_my_account_get_addresses', array( $get_addresses = apply_filters( 'woocommerce_my_account_get_addresses', array(
'billing' => __( 'Billing Address', 'woocommerce' ) 'billing' => __( 'Billing Address', 'woocommerce' )
), $customer_id ); ), $customer_id );
} }
@ -50,7 +50,7 @@ $col = 1;
<div class="col-<?php echo ( ( $col = $col * -1 ) < 0 ) ? 1 : 2; ?> address"> <div class="col-<?php echo ( ( $col = $col * -1 ) < 0 ) ? 1 : 2; ?> address">
<header class="title"> <header class="title">
<h3><?php echo $title; ?></h3> <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> </header>
<address> <address>
<?php <?php

View File

@ -21,8 +21,7 @@ if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
$customer_orders = new WP_Query( wc_get_account_orders_query_args() ); $customer_orders = new WP_Query( wc_get_account_orders_query_args( $current_page ) );
$current_page = isset( $_GET['orders-page'] ) ? absint( $_GET['orders-page'] ) : 1;
wc_get_template( 'myaccount/navigation.php' ); ?> wc_get_template( 'myaccount/navigation.php' ); ?>
@ -104,11 +103,11 @@ wc_get_template( 'myaccount/navigation.php' ); ?>
<?php if ( 1 < $customer_orders->max_num_pages ) : ?> <?php if ( 1 < $customer_orders->max_num_pages ) : ?>
<div class="wc-account-orders-pagination"> <div class="wc-account-orders-pagination">
<?php if ( 1 !== $current_page ) : ?> <?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 endif; ?>
<?php if ( $current_page !== intval( $customer_orders->max_num_pages ) ) : ?> <?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; ?> <?php endif; ?>
</div> </div>
<?php endif; ?> <?php endif; ?>