我想根据客户的总消费金额自动应用优惠券。此优惠券仅需由客户使用一次。到目前为止,这是我尝试过的操作,但是出现黑屏:add_action( 'woocommerce_before_calculate_totals', 'loyalty_order_discount', 10, 1 );function loyalty_order_discount( $order_id ) { global $woocommerce; $coupon = 'loyaltydiscount'; $customer = new WC_Customer(get_current_user_id()); $total_spent = 30; $order = wc_get_order( $order_id ); foreach( $order->get_used_coupons( $customer ) as $coupon_name ){ // Retrieving the coupon ID $coupon_post_obj = get_page_by_title($coupon_name, OBJECT, 'shop_coupon'); $coupon_id = $coupon_post_obj->ID; $coupons_obj = new WC_Coupon($coupon_id); if( $coupons_obj == $coupon && $customer->get_total_spent() < $total_spent ){ $woocommerce->cart->remove_coupon( $coupon ); } elseif ( ! $coupons_obj == $coupon && $customer->get_total_spent() >= $total_spent){ $woocommerce->cart->add_discount( $coupon ); } }}任何帮助表示赞赏。
1 回答
- 1 回答
- 0 关注
- 167 浏览
添加回答
举报
0/150
提交
取消