WC_Coupon_Data_Store_CPT::decrease_usage_count
Decrease usage count for current coupon.
Метод класса: WC_Coupon_Data_Store_CPT{}
Хуки из метода
Возвращает
int. New usage count.
Использование
$WC_Coupon_Data_Store_CPT = new WC_Coupon_Data_Store_CPT(); $WC_Coupon_Data_Store_CPT->decrease_usage_count( $coupon, $used_by );
- $coupon(WC_Coupon) (обязательный) (передается по ссылке — &)
- Coupon object.
- $used_by(строка)
- Either user ID or billing email.
По умолчанию:''
Список изменений
| С версии 3.0.0 | Введена. |
Код WC_Coupon_Data_Store_CPT::decrease_usage_count() WC Coupon Data Store CPT::decrease usage count WC 11.0.1
public function decrease_usage_count( &$coupon, $used_by = '' ) {
global $wpdb;
$new_count = $this->update_usage_count_meta( $coupon, 'decrease' );
if ( $used_by ) {
/**
* We're doing this the long way because `delete_post_meta( $id, $key, $value )` deletes.
* all instances where the key and value match, and we only want to delete one.
*/
$meta_id = $wpdb->get_var(
$wpdb->prepare(
"SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_used_by' AND meta_value = %s AND post_id = %d LIMIT 1;",
$used_by,
$coupon->get_id()
)
);
if ( $meta_id ) {
delete_metadata_by_mid( 'post', $meta_id );
$coupon->set_used_by( (array) get_post_meta( $coupon->get_id(), '_used_by' ) );
$this->refresh_coupon_data( $coupon );
}
}
do_action( 'woocommerce_decrease_coupon_usage_count', $coupon, $new_count, $used_by );
return $new_count;
}