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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / admin / reports / class-wc-report-customer-list.php
woocommerce / includes / admin / reports Last commit date
class-wc-admin-report.php 1 year ago class-wc-report-coupon-usage.php 5 years ago class-wc-report-customer-list.php 9 months ago class-wc-report-customers.php 9 months ago class-wc-report-downloads.php 5 years ago class-wc-report-low-in-stock.php 5 years ago class-wc-report-most-stocked.php 5 years ago class-wc-report-out-of-stock.php 5 years ago class-wc-report-sales-by-category.php 2 years ago class-wc-report-sales-by-date.php 1 year ago class-wc-report-sales-by-product.php 3 months ago class-wc-report-stock.php 1 year ago class-wc-report-taxes-by-code.php 1 year ago class-wc-report-taxes-by-date.php 1 year ago
class-wc-report-customer-list.php
299 lines
1 <?php
2 /**
3 * Class WC_Report_Customer_List file.
4 *
5 * @package WooCommerce\Reports
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 if ( ! class_exists( 'WP_List_Table' ) ) {
13 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
14 }
15
16 /**
17 * WC_Report_Customer_List.
18 *
19 * @package WooCommerce\Admin\Reports
20 * @version 2.1.0
21 */
22 class WC_Report_Customer_List extends WP_List_Table {
23
24 /**
25 * Constructor.
26 */
27 public function __construct() {
28
29 parent::__construct(
30 array(
31 'singular' => 'customer',
32 'plural' => 'customers',
33 'ajax' => false,
34 )
35 );
36 }
37
38 /**
39 * No items found text.
40 */
41 public function no_items() {
42 esc_html_e( 'No customers found.', 'woocommerce' );
43 }
44
45 /**
46 * Output the report.
47 */
48 public function output_report() {
49 $this->prepare_items();
50
51 echo '<div id="poststuff" class="woocommerce-reports-wide">';
52
53 if ( ! empty( $_GET['link_orders'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'], 'link_orders' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
54 $linked = wc_update_new_customer_past_orders( absint( $_GET['link_orders'] ) );
55 /* translators: single or plural number of orders */
56 echo '<div class="updated"><p>' . esc_html( sprintf( _n( '%s previous order linked', '%s previous orders linked', $linked, 'woocommerce' ), $linked ) ) . '</p></div>';
57 }
58
59 if ( ! empty( $_GET['refresh'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'], 'refresh' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
60 $user_id = absint( $_GET['refresh'] );
61 $user = get_user_by( 'id', $user_id );
62
63 delete_user_meta( $user_id, '_money_spent' );
64 delete_user_meta( $user_id, '_order_count' );
65 delete_user_meta( $user_id, '_last_order' );
66 /* translators: User display name */
67 echo '<div class="updated"><p>' . sprintf( esc_html__( 'Refreshed stats for %s', 'woocommerce' ), esc_html( $user->display_name ) ) . '</p></div>';
68 }
69
70 echo '<form method="post" id="woocommerce_customers">';
71
72 $this->search_box( __( 'Search customers', 'woocommerce' ), 'customer_search' );
73 $this->display();
74
75 echo '</form>';
76 echo '</div>';
77 }
78
79 /**
80 * Get column value.
81 *
82 * @param WP_User $user WP User object.
83 * @param string $column_name Column name.
84 * @return string
85 */
86 public function column_default( $user, $column_name ) {
87 switch ( $column_name ) {
88
89 case 'customer_name':
90 if ( $user->last_name && $user->first_name ) {
91 return $user->last_name . ', ' . $user->first_name;
92 } else {
93 return '-';
94 }
95
96 case 'username':
97 return $user->user_login;
98
99 case 'location':
100 $state_code = get_user_meta( $user->ID, 'billing_state', true );
101 $country_code = get_user_meta( $user->ID, 'billing_country', true );
102
103 $state = isset( WC()->countries->states[ $country_code ][ $state_code ] ) ? WC()->countries->states[ $country_code ][ $state_code ] : $state_code;
104 $country = isset( WC()->countries->countries[ $country_code ] ) ? WC()->countries->countries[ $country_code ] : $country_code;
105
106 $value = '';
107
108 if ( $state ) {
109 $value .= $state . ', ';
110 }
111
112 $value .= $country;
113
114 if ( $value ) {
115 return $value;
116 } else {
117 return '-';
118 }
119
120 case 'email':
121 return '<a href="mailto:' . $user->user_email . '">' . $user->user_email . '</a>';
122
123 case 'spent':
124 return wc_price( wc_get_customer_total_spent( $user->ID ) );
125
126 case 'orders':
127 return wc_get_customer_order_count( $user->ID );
128
129 case 'last_order':
130 $orders = wc_get_orders(
131 array(
132 'limit' => 1,
133 'status' => array_map( 'wc_get_order_status_name', wc_get_is_paid_statuses() ),
134 'customer' => $user->ID,
135 )
136 );
137
138 if ( ! empty( $orders ) ) {
139 $order = $orders[0];
140 return '<a href="' . admin_url( 'post.php?post=' . $order->get_id() . '&action=edit' ) . '">' . _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number() . '</a> &ndash; ' . wc_format_datetime( $order->get_date_created() );
141 } else {
142 return '-';
143 }
144
145 break;
146
147 case 'wc_actions':
148 ob_start();
149 ?><p>
150 <?php
151 do_action( 'woocommerce_admin_user_actions_start', $user );
152
153 $actions = array();
154
155 $actions['refresh'] = array(
156 'url' => wp_nonce_url( add_query_arg( 'refresh', $user->ID ), 'refresh' ),
157 'name' => __( 'Refresh stats', 'woocommerce' ),
158 'action' => 'refresh',
159 );
160
161 $actions['edit'] = array(
162 'url' => admin_url( 'user-edit.php?user_id=' . $user->ID ),
163 'name' => __( 'Edit', 'woocommerce' ),
164 'action' => 'edit',
165 );
166
167 $actions['view'] = array(
168 'url' => admin_url( 'edit.php?post_type=shop_order&_customer_user=' . $user->ID ),
169 'name' => __( 'View orders', 'woocommerce' ),
170 'action' => 'view',
171 );
172
173 $orders = wc_get_orders(
174 array(
175 'limit' => 1,
176 'status' => array_map( 'wc_get_order_status_name', wc_get_is_paid_statuses() ),
177 'customer' => array( array( 0, $user->user_email ) ),
178 )
179 );
180
181 if ( $orders ) {
182 $actions['link'] = array(
183 'url' => wp_nonce_url( add_query_arg( 'link_orders', $user->ID ), 'link_orders' ),
184 'name' => __( 'Link previous orders', 'woocommerce' ),
185 'action' => 'link',
186 );
187 }
188
189 $actions = apply_filters( 'woocommerce_admin_user_actions', $actions, $user );
190
191 foreach ( $actions as $action ) {
192 printf( '<a class="button tips %s" href="%s" data-tip="%s">%s</a>', esc_attr( $action['action'] ), esc_url( $action['url'] ), esc_attr( $action['name'] ), esc_attr( $action['name'] ) );
193 }
194
195 do_action( 'woocommerce_admin_user_actions_end', $user );
196 ?>
197 </p>
198 <?php
199 $user_actions = ob_get_contents();
200 ob_end_clean();
201
202 return $user_actions;
203 }
204
205 return '';
206 }
207
208 /**
209 * Get columns.
210 *
211 * @return array
212 */
213 public function get_columns() {
214 $columns = array(
215 'customer_name' => __( 'Name (Last, First)', 'woocommerce' ),
216 'username' => __( 'Username', 'woocommerce' ),
217 'email' => __( 'Email', 'woocommerce' ),
218 'location' => __( 'Location', 'woocommerce' ),
219 'orders' => __( 'Orders', 'woocommerce' ),
220 'spent' => __( 'Money spent', 'woocommerce' ),
221 'last_order' => __( 'Last order', 'woocommerce' ),
222 'wc_actions' => __( 'Actions', 'woocommerce' ),
223 );
224
225 return $columns;
226 }
227
228 /**
229 * Order users by name.
230 *
231 * @param WP_User_Query $query Query that gets passed through.
232 * @return WP_User_Query
233 */
234 public function order_by_last_name( $query ) {
235 global $wpdb;
236
237 $s = ! empty( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
238
239 $query->query_from .= " LEFT JOIN {$wpdb->usermeta} as meta2 ON ({$wpdb->users}.ID = meta2.user_id) ";
240 $query->query_where .= " AND meta2.meta_key = 'last_name' ";
241 $query->query_orderby = ' ORDER BY meta2.meta_value, user_login ASC ';
242
243 if ( $s ) {
244 $query->query_from .= " LEFT JOIN {$wpdb->usermeta} as meta3 ON ({$wpdb->users}.ID = meta3.user_id)";
245 $query->query_where .= " AND ( user_login LIKE '%" . esc_sql( str_replace( '*', '', $s ) ) . "%' OR user_nicename LIKE '%" . esc_sql( str_replace( '*', '', $s ) ) . "%' OR meta3.meta_value LIKE '%" . esc_sql( str_replace( '*', '', $s ) ) . "%' ) ";
246 $query->query_orderby = ' GROUP BY ID ' . $query->query_orderby;
247 }
248
249 return $query;
250 }
251
252 /**
253 * Prepare customer list items.
254 */
255 public function prepare_items() {
256 $current_page = absint( $this->get_pagenum() );
257 $per_page = 20;
258
259 /**
260 * Init column headers.
261 */
262 $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns() );
263
264 add_action( 'pre_user_query', array( $this, 'order_by_last_name' ) );
265
266 $privileged_users = new WP_User_Query(
267 array(
268 'fields' => 'ID',
269 'role__in' => array( 'administrator', 'shop_manager' ),
270 ),
271 );
272 $query = new WP_User_Query(
273 apply_filters(
274 'woocommerce_admin_report_customer_list_user_query_args',
275 array(
276 'exclude' => $privileged_users->get_results(),
277 'number' => $per_page,
278 'offset' => ( $current_page - 1 ) * $per_page,
279 )
280 )
281 );
282
283 $this->items = $query->get_results();
284
285 remove_action( 'pre_user_query', array( $this, 'order_by_last_name' ) );
286
287 /**
288 * Pagination.
289 */
290 $this->set_pagination_args(
291 array(
292 'total_items' => $query->total_users,
293 'per_page' => $per_page,
294 'total_pages' => ceil( $query->total_users / $per_page ),
295 )
296 );
297 }
298 }
299