Automattic\WooCommerce\Admin\API\Reports\Customers
DataStore::get_order_count()
Retrieve the amount of orders made by a customer.
Method of the class: DataStore{}
No Hooks.
Return
Int|null
. Amount of orders for customer or null on failure.
Usage
$result = DataStore::get_order_count( $customer_id );
- $customer_id(int) (required)
- Customer ID.
DataStore::get_order_count() DataStore::get order count code WC 9.3.3
public static function get_order_count( $customer_id ) { global $wpdb; $customer_id = absint( $customer_id ); if ( 0 === $customer_id ) { return null; } $result = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( order_id ) FROM {$wpdb->prefix}wc_order_stats WHERE customer_id = %d", $customer_id ) ); if ( is_null( $result ) ) { return null; } return (int) $result; }