parent
333a391406
commit
d3f98dce03
|
@ -125,24 +125,14 @@ class WC_Report_Customer_List extends WP_List_Table {
|
|||
|
||||
case 'last_order' :
|
||||
|
||||
$order_ids = get_posts( array(
|
||||
'posts_per_page' => 1,
|
||||
'post_type' => 'shop_order',
|
||||
'orderby' => 'date',
|
||||
'order' => 'desc',
|
||||
'post_status' => array( 'wc-completed', 'wc-processing' ),
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => '_customer_user',
|
||||
'value' => $user->ID
|
||||
)
|
||||
),
|
||||
'fields' => 'ids'
|
||||
$orders = wc_get_orders( array(
|
||||
'limit' => 1,
|
||||
'status' => array( 'wc-completed', 'wc-processing' ),
|
||||
'customer' => $user->ID
|
||||
) );
|
||||
|
||||
if ( $order_ids ) {
|
||||
$order = wc_get_order( $order_ids[0] );
|
||||
|
||||
if ( ! empty( $orders->orders ) ) {
|
||||
$order = $orders->orders[0];
|
||||
return '<a href="' . admin_url( 'post.php?post=' . $order->id . '&action=edit' ) . '">' . _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number() . '</a> – ' . date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) );
|
||||
} else {
|
||||
return '-';
|
||||
|
@ -176,25 +166,13 @@ class WC_Report_Customer_List extends WP_List_Table {
|
|||
'action' => "view"
|
||||
);
|
||||
|
||||
$order_ids = get_posts( array(
|
||||
'posts_per_page' => 1,
|
||||
'post_type' => wc_get_order_types(),
|
||||
'post_status' => array_keys( wc_get_order_statuses() ),
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => '_customer_user',
|
||||
'value' => array( 0, '' ),
|
||||
'compare' => 'IN'
|
||||
),
|
||||
array(
|
||||
'key' => '_billing_email',
|
||||
'value' => $user->user_email
|
||||
)
|
||||
),
|
||||
'fields' => 'ids'
|
||||
$orders = wc_get_orders( array(
|
||||
'limit' => 1,
|
||||
'status' => array( 'wc-completed', 'wc-processing' ),
|
||||
'customer' => array( array( 0, $user->user_email ) ),
|
||||
) );
|
||||
|
||||
if ( $order_ids ) {
|
||||
if ( $orders->total > 0 ) {
|
||||
$actions['link'] = array(
|
||||
'url' => wp_nonce_url( add_query_arg( 'link_orders', $user->ID ), 'link_orders' ),
|
||||
'name' => __( 'Link previous orders', 'woocommerce' ),
|
||||
|
|
|
@ -24,7 +24,9 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
* status array|string List of order statuses to find
|
||||
* type array|string Order type, e.g. shop_order or shop_order_refund
|
||||
* parent int post/order parent
|
||||
* customer int|string User ID or billing email to limit orders to a particular user.
|
||||
* customer int|string|array User ID or billing email to limit orders to a
|
||||
* particular user. Accepts array of values. Array of values is OR'ed. If array of array is passed, each array will be AND'ed.
|
||||
* e.g. test@test.com, 1, array( 1, 2, 3 ), array( array( 1, 'test@test.com' ), 2, 3 )
|
||||
* limit int Maximum of orders to retrieve.
|
||||
* offset int Offset of orders to retrieve.
|
||||
* page int Page of orders to retrieve. Ignored when using the 'offset' arg.
|
||||
|
@ -43,6 +45,7 @@ function wc_get_orders( $args ) {
|
|||
'type' => wc_get_order_types( 'view-orders' ),
|
||||
'parent' => null,
|
||||
'customer' => 0,
|
||||
'email' => '',
|
||||
'limit' => 10,
|
||||
'offset' => null,
|
||||
'page' => 1,
|
||||
|
@ -86,17 +89,8 @@ function wc_get_orders( $args ) {
|
|||
}
|
||||
|
||||
if ( ! empty( $args['customer'] ) ) {
|
||||
if ( is_email( $args['customer'] ) ) {
|
||||
$wp_query_args['meta_query'][] = array(
|
||||
'key' => '_billng_email',
|
||||
'value' => sanitize_email( $args['customer'] ),
|
||||
);
|
||||
} else {
|
||||
$wp_query_args['meta_query'][] = array(
|
||||
'key' => '_customer_user',
|
||||
'value' => absint( $args['customer'] ),
|
||||
);
|
||||
}
|
||||
$values = is_array( $args['customer'] ) ? $args['customer'] : array( $args['customer'] );
|
||||
$wp_query_args['meta_query'][] = _wc_get_orders_generate_customer_meta_query( $values );
|
||||
}
|
||||
|
||||
if ( ! empty( $args['exclude'] ) ) {
|
||||
|
@ -114,11 +108,55 @@ function wc_get_orders( $args ) {
|
|||
|
||||
return (object) array(
|
||||
'orders' => $return,
|
||||
'total_orders' => $orders->found_posts,
|
||||
'total' => $orders->found_posts,
|
||||
'max_num_pages' => $orders->max_num_pages,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate meta query for wc_get_orders. Used internally only.
|
||||
* @since 2.6.0
|
||||
* @param array $values
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
function _wc_get_orders_generate_customer_meta_query( $values, $relation = 'or' ) {
|
||||
$meta_query = array(
|
||||
'relation' => strtoupper( $relation ),
|
||||
'customer_emails' => array(
|
||||
'key' => '_billing_email',
|
||||
'value' => array(),
|
||||
'compare' => 'IN'
|
||||
),
|
||||
'customer_ids' => array(
|
||||
'key' => '_customer_user',
|
||||
'value' => array(),
|
||||
'compare' => 'IN'
|
||||
)
|
||||
);
|
||||
foreach ( $values as $value ) {
|
||||
if ( is_array( $value ) ) {
|
||||
$meta_query[] = _wc_get_orders_generate_customer_meta_query( $value, 'and' );
|
||||
} elseif ( is_email( $value ) ) {
|
||||
$meta_query['customer_emails']['value'][] = sanitize_email( $value );
|
||||
} else {
|
||||
$meta_query['customer_ids']['value'][] = strval( absint( $value ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $meta_query['customer_emails']['value'] ) ) {
|
||||
unset( $meta_query['customer_emails'] );
|
||||
unset( $meta_query['relation'] );
|
||||
}
|
||||
|
||||
if ( empty( $meta_query['customer_ids']['value'] ) ) {
|
||||
unset( $meta_query['customer_ids'] );
|
||||
unset( $meta_query['relation'] );
|
||||
}
|
||||
|
||||
return $meta_query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all order statuses.
|
||||
*
|
||||
|
|
|
@ -2,21 +2,7 @@
|
|||
/**
|
||||
* My Orders
|
||||
*
|
||||
* Shows recent orders on the account page.
|
||||
*
|
||||
* This template can be overridden by copying it to yourtheme/woocommerce/myaccount/my-orders.php.
|
||||
*
|
||||
* HOWEVER, on occasion WooCommerce will need to update template files and you
|
||||
* (the theme developer) will need to copy the new files to your theme to
|
||||
* maintain compatibility. We try to do this as little as possible, but it does
|
||||
* happen. When this occurs the version of the template file will be bumped and
|
||||
* the readme will list any important changes.
|
||||
*
|
||||
* @see http://docs.woothemes.com/document/template-structure/
|
||||
* @author WooThemes
|
||||
* @package WooCommerce/Templates
|
||||
* @version 2.5.0
|
||||
* @deprecated 2.6.0
|
||||
* @deprecated 2.6.0 this template file is no longer used. My Account shortcode uses orders.php.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
|
|
@ -29,7 +29,7 @@ wc_get_template( 'myaccount/navigation.php' ); ?>
|
|||
|
||||
<?php do_action( 'woocommerce_before_account_orders', $customer_orders ); ?>
|
||||
|
||||
<?php if ( 0 < $customer_orders->total_orders ) : ?>
|
||||
<?php if ( 0 < $customer_orders->total ) : ?>
|
||||
|
||||
<table class="shop_table shop_table_responsive my_account_orders account-orders-table">
|
||||
<thead>
|
||||
|
|
Loading…
Reference in New Issue