WC_Coupon_Data_Store_CPT::get_usage_by_email()publicWC 3.6.4

Get the number of uses for a coupon by email address

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_email( $coupon, $email );
$coupon(WC_Coupon) (required) (passed by reference — &)
Coupon object.
$email(string) (required)
Email address.

Changelog

Since 3.6.4 Introduced.

WC_Coupon_Data_Store_CPT::get_usage_by_email() code WC 9.3.3

public function get_usage_by_email( &$coupon, $email ) {
	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 = %s;",
			$coupon->get_id(),
			$email
		)
	);
	$tentative_usage_count = $this->get_tentative_usages_for_user( $coupon->get_id(), array( $email ) );
	return $tentative_usage_count + $usage_count;
}