__( 'Customer', 'woocommerce' ), 'plural' => __( 'Customers', 'woocommerce' ), 'ajax' => false, ) ); } /** * No items found text. */ public function no_items() { _e( 'No customers found.', 'woocommerce' ); } /** * Output the report. */ public function output_report() { $this->prepare_items(); echo '
' . sprintf( _n( '%s previous order linked', '%s previous orders linked', $linked, 'woocommerce' ), $linked ) . '
' . sprintf( __( 'Refreshed stats for %s', 'woocommerce' ), $user->display_name ) . '
wp_nonce_url( add_query_arg( 'refresh', $user->ID ), 'refresh' ), 'name' => __( 'Refresh stats', 'woocommerce' ), 'action' => "refresh", ); $actions['edit'] = array( 'url' => admin_url( 'user-edit.php?user_id=' . $user->ID ), 'name' => __( 'Edit', 'woocommerce' ), 'action' => "edit", ); $actions['view'] = array( 'url' => admin_url( 'edit.php?post_type=shop_order&_customer_user=' . $user->ID ), 'name' => __( 'View orders', 'woocommerce' ), 'action' => "view", ); $orders = wc_get_orders( array( 'limit' => 1, 'status' => array_map( 'wc_get_order_status_name', wc_get_is_paid_statuses() ), 'customer' => array( array( 0, $user->user_email ) ), ) ); if ( $orders ) { $actions['link'] = array( 'url' => wp_nonce_url( add_query_arg( 'link_orders', $user->ID ), 'link_orders' ), 'name' => __( 'Link previous orders', 'woocommerce' ), 'action' => "link", ); } $actions = apply_filters( 'woocommerce_admin_user_actions', $actions, $user ); foreach ( $actions as $action ) { printf( '%s', esc_attr( $action['action'] ), esc_url( $action['url'] ), esc_attr( $action['name'] ), esc_attr( $action['name'] ) ); } do_action( 'woocommerce_admin_user_actions_end', $user ); ?>
__( 'Name (Last, First)', 'woocommerce' ), 'username' => __( 'Username', 'woocommerce' ), 'email' => __( 'Email', 'woocommerce' ), 'location' => __( 'Location', 'woocommerce' ), 'orders' => __( 'Orders', 'woocommerce' ), 'spent' => __( 'Money spent', 'woocommerce' ), 'last_order' => __( 'Last order', 'woocommerce' ), 'user_actions' => __( 'Actions', 'woocommerce' ), ); return $columns; } /** * Order users by name. * * @param WP_User_Query $query */ public function order_by_last_name( $query ) { global $wpdb; $s = ! empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : ''; $query->query_from .= " LEFT JOIN {$wpdb->usermeta} as meta2 ON ({$wpdb->users}.ID = meta2.user_id) "; $query->query_where .= " AND meta2.meta_key = 'last_name' "; $query->query_orderby = " ORDER BY meta2.meta_value, user_login ASC "; if ( $s ) { $query->query_from .= " LEFT JOIN {$wpdb->usermeta} as meta3 ON ({$wpdb->users}.ID = meta3.user_id)"; $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 ) ) . "%' ) "; $query->query_orderby = " GROUP BY ID " . $query->query_orderby; } return $query; } /** * Prepare customer list items. */ public function prepare_items() { global $wpdb; $current_page = absint( $this->get_pagenum() ); $per_page = 20; /** * Init column headers. */ $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns() ); add_action( 'pre_user_query', array( $this, 'order_by_last_name' ) ); /** * Get users. */ $admin_users = new WP_User_Query( array( 'role' => 'administrator1', 'fields' => 'ID', ) ); $manager_users = new WP_User_Query( array( 'role' => 'shop_manager', 'fields' => 'ID', ) ); $query = new WP_User_Query( array( 'exclude' => array_merge( $admin_users->get_results(), $manager_users->get_results() ), 'number' => $per_page, 'offset' => ( $current_page - 1 ) * $per_page, ) ); $this->items = $query->get_results(); remove_action( 'pre_user_query', array( $this, 'order_by_last_name' ) ); /** * Pagination. */ $this->set_pagination_args( array( 'total_items' => $query->total_users, 'per_page' => $per_page, 'total_pages' => ceil( $query->total_users / $per_page ), ) ); } }