WordPress at Your Fingertips
function is not described

WC_Customer_Data_Store::get_order_count() public WC 3.0.0

Return the number of orders this customer has.

{} It's a method of the class: WC_Customer_Data_Store{}

Hooks from the method
Return

Int.

Usage

$WC_Customer_Data_Store = new WC_Customer_Data_Store();
$WC_Customer_Data_Store->get_order_count( $customer );
$customer(WC_Customer) (required) (passed by reference — &)
Customer object.

Changelog

Since 3.0.0 Introduced.

Code of WC_Customer_Data_Store::get_order_count() WC 5.6.0

public function get_order_count( &$customer ) {
	$count = apply_filters(
		'woocommerce_customer_get_order_count',
		get_user_meta( $customer->get_id(), '_order_count', true ),
		$customer
	);

	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 );
}