WC_Customer_Data_Store::get_order_count( WC_Customer $customer )
Return the number of orders this customer has.
Description Description
Parameters Parameters
- $customer
-
(Required) Customer object.
Return Return
(integer)
Source Source
File: includes/data-stores/class-wc-customer-data-store.php
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | public function get_order_count( & $customer ) { $count = get_user_meta( $customer ->get_id(), '_order_count' , true ); if ( '' === $count ) { global $wpdb ; $count = $wpdb ->get_var( // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared "SELECT COUNT (*) FROM $wpdb ->posts as posts LEFT JOIN { $wpdb ->postmeta} AS meta ON posts.ID = meta.post_id WHERE meta.meta_key = '_customer_user' AND posts.post_type = 'shop_order' AND posts.post_status IN ( '" . implode( "' , '", array_map( ' esc_sql ', array_keys( wc_get_order_statuses() ) ) ) . "' ) AND meta_value = '" . esc_sql( $customer->get_id() ) . "' " // phpcs:enable ); update_user_meta( $customer ->get_id(), '_order_count' , $count ); } return absint( $count ); } |
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |