WC_Coupon_Data_Store_CPT::get_tentative_usage_query()privateWC 1.0

Generate query to calculate tentative usages for the coupon.

Method of the class: WC_Coupon_Data_Store_CPT{}

No Hooks.

Return

String. Query for tentative usages.

Usage

// private - for code of main (parent) class only
$result = $this->get_tentative_usage_query( $coupon_id );
$coupon_id(int) (required)
Coupon ID to get tentative usage query for.

WC_Coupon_Data_Store_CPT::get_tentative_usage_query() code WC 8.6.1

private function get_tentative_usage_query( $coupon_id ) {
	global $wpdb;
	return $wpdb->prepare(
		"
		SELECT COUNT(meta_id) FROM $wpdb->postmeta
		WHERE {$wpdb->postmeta}.meta_key like %s
		AND {$wpdb->postmeta}.meta_key > %s
		AND {$wpdb->postmeta}.post_id = %d
		FOR UPDATE
		",
		array(
			'_coupon_held_%',
			'_coupon_held_' . time(),
			$coupon_id,
		)
	);  // WPCS: unprepared SQL ok.
}