WC_Coupon_Data_Store_CPT::get_tentative_usage_query_for_user
Generate query to calculate tentative usages for the coupon by the user.
Метод класса: WC_Coupon_Data_Store_CPT{}
Хуков нет.
Возвращает
Строку. Tentative usages query.
Использование
// private - только в коде основоного (родительского) класса $result = $this->get_tentative_usage_query_for_user( $coupon_id, $user_aliases );
- $coupon_id(int) (обязательный)
- Coupon ID.
- $user_aliases(массив) (обязательный)
- List of user aliases to check for usages.
Код WC_Coupon_Data_Store_CPT::get_tentative_usage_query_for_user() WC Coupon Data Store CPT::get tentative usage query for user WC 10.7.0
private function get_tentative_usage_query_for_user( $coupon_id, $user_aliases ) {
global $wpdb;
$format = implode( "','", array_fill( 0, count( $user_aliases ), '%s' ) );
// Note that if you are debugging, `_maybe_used_by_%` will be converted to `_maybe_used_by_{...very long str...}` to very long string. This is expected, and is automatically corrected while running the insert query.
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
AND {$wpdb->postmeta}.meta_value IN ('$format')
FOR UPDATE
",
array_merge(
array(
'_maybe_used_by_%',
'_maybe_used_by_' . time(),
$coupon_id,
),
$user_aliases
)
); // WPCS: unprepared SQL ok.
}