تابع wc_update_coupon_usage_counts بروزرسانی میزان استفاده تعداد کوپن ووکامرس

تابع ووکامرسی wc_update_coupon_usage_counts – بروزرسانی میزان استفاده تعداد کوپن ووکامرس
Syntax – سینتکس
wc_update_coupon_usage_counts( (int) $order_id );
Parameters – پارامتر ها (1)
- 1- $order_id (int)
Usage – نحوه استفاده
if ( !function_exists( 'wc_update_coupon_usage_counts' ) ) {
require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-order-functions.php';
}
// The order id.
$order_id = -1;
// NOTICE! Understand what this does before running.
$result = wc_update_coupon_usage_counts($order_id);
Defined – محل تعریف
/includes/wc-order-functions.php
function wc_update_coupon_usage_counts( $order_id ) {
if ( ! $order = wc_get_order( $order_id ) ) {
return;
}
$has_recorded = $order->get_data_store()->get_recorded_coupon_usage_counts( $order );
if ( $order->has_status( 'cancelled' ) && $has_recorded ) {
$action = 'reduce';
$order->get_data_store()->set_recorded_coupon_usage_counts( $order, false );
} elseif ( ! $order->has_status( 'cancelled' ) && ! $has_recorded ) {
$action = 'increase';
$order->get_data_store()->set_recorded_coupon_usage_counts( $order, true );
} else {
return;
}
if ( sizeof( $order->get_used_coupons() ) > 0 ) {
foreach ( $order->get_used_coupons() as $code ) {
if ( ! $code ) {
continue;
}
$coupon = new WC_Coupon( $code );
if ( ! $used_by = $order->get_user_id() ) {
$used_by = $order->get_billing_email();
}
switch ( $action ) {
case 'reduce' :
$coupon->decrease_usage_count( $used_by );
break;
case 'increase' :
$coupon->increase_usage_count( $used_by );
break;
}
}
}
}
versions – نسخه ها
از نسخه : 3.0.0
نسخه فعلی : 3.0.6
دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2
ارسال نظر