WordPress at Your Fingertips
function is not described

WC_Coupon_Data_Store_CPT::get_usage_by_user_id() public WC 3.0.0

Get the number of uses for a coupon by user ID.

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

No Hooks.

Return

Int.

Usage

$WC_Coupon_Data_Store_CPT = new WC_Coupon_Data_Store_CPT();
$WC_Coupon_Data_Store_CPT->get_usage_by_user_id( $coupon, $user_id );
$coupon(WC_Coupon) (required) (passed by reference — &)
Coupon object.
$user_id(int) (required)
User ID.

Changelog

Since 3.0.0 Introduced.

Code of WC_Coupon_Data_Store_CPT::get_usage_by_user_id() WC 5.6.0

public function get_usage_by_user_id( &$coupon, $user_id ) {
	global $wpdb;
	$usage_count = $wpdb->get_var(
		$wpdb->prepare(
			"SELECT COUNT( meta_id ) FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = '_used_by' AND meta_value = %d;",
			$coupon->get_id(),
			$user_id
		)
	);
	$tentative_usage_count = $this->get_tentative_usages_for_user( $coupon->get_id(), array( $user_id ) );
	return $tentative_usage_count + $usage_count;
}