优惠券订阅PHP

问题描述 投票:0回答:1

我发现这一段可将优惠券以编程的顺序:

// Create the coupon
global $woocommerce;
$coupon = new WC_Coupon($coupon_code);

// Get the coupon discount amount (My coupon is a fixed value off)
$discount_total = $coupon->get_amount();

// Loop through products and apply the coupon discount
foreach($order->get_items() as $order_item){
    $product_id = $order_item->get_product_id();

    if($this->coupon_applies_to_product($coupon, $product_id)){
        $total = $order_item->get_total();
        $order_item->set_subtotal($total);
        $order_item->set_total($total - $discount_total);
        $order_item->save();
    }
}
$order->save();

它工作得很好。不过,我想优惠券应用到现有的订阅,这样当它更新,优惠券将被应用到将被自动创建的订单。

有没有办法做到这一点?

谢谢!

php woocommerce woocommerce-subscriptions
1个回答
0
投票

听起来像是你也许想安装一个脚本在给定的时间间隔运行,检查订阅,创建订单和适用优惠券。根据您正在运行的系统,你可能想看看在Linux或Windows Windows任务调度的cron为了定期执行脚本。

© www.soinside.com 2019 - 2024. All rights reserved.