Better pagination for account > orders
This commit is contained in:
parent
da9638c137
commit
0c27f9bf1e
|
@ -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' );
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 );
|
||||||
|
|
|
@ -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 ) ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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; ?>
|
||||||
|
|
Loading…
Reference in New Issue