Skip to content

Commit

Permalink
Better pagination for account > orders
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiosanches committed Jan 20, 2016
1 parent da9638c commit 0c27f9b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions includes/class-wc-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public function get_endpoint_title( $endpoint ) {
$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' );
}
Expand Down
8 changes: 5 additions & 3 deletions includes/wc-account-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 );
Expand Down
8 changes: 6 additions & 2 deletions includes/wc-template-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2029,9 +2029,13 @@ function wc_dropdown_variation_attribute_options( $args = array() ) {

/**
* 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 ) ) );
}
}

Expand Down
6 changes: 3 additions & 3 deletions templates/myaccount/my-address.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@

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' ) );
$get_addresses = apply_filters( 'woocommerce_my_account_get_addresses', array(
$get_addresses = apply_filters( 'woocommerce_my_account_get_addresses', array(
'billing' => __( 'Billing Address', 'woocommerce' ),
'shipping' => __( 'Shipping Address', 'woocommerce' )
), $customer_id );
} else {
$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' )
), $customer_id );
}
Expand All @@ -50,7 +50,7 @@
<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
Expand Down
7 changes: 3 additions & 4 deletions templates/myaccount/orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
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' ); ?>

Expand Down Expand Up @@ -104,11 +103,11 @@
<?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; ?>
Expand Down

0 comments on commit 0c27f9b

Please sign in to comment.