WC_Coupon_Data_Store_CPT::get_usage_by_user_id()publicWC 3.0.0

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

Метод класса: WC_Coupon_Data_Store_CPT{}

Хуков нет.

Возвращает

int.

Использование

$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) (обязательный) (передается по ссылке — &)
Coupon object.
$user_id(int) (обязательный)
User ID.

Список изменений

С версии 3.0.0 Введена.

Код WC_Coupon_Data_Store_CPT::get_usage_by_user_id() WC 8.7.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 = %s;",
			$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;
}