WC_Coupon_Data_Store_CPT::get_usage_by_user_id( WC_Coupon $coupon, int $user_id )
Get the number of uses for a coupon by user ID.
Description Description
Parameters Parameters
- $coupon
-
(Required) Coupon object.
- $user_id
-
(Required) User ID.
Return Return
(int)
Source Source
File: includes/data-stores/class-wc-coupon-data-store-cpt.php
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;
}
Changelog Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |