【发布时间】:2018-10-07 20:35:14
【问题描述】:
我正在尝试创建一个功能,无论购物车中有什么产品或有多少产品,都可以将购物车折扣设置为 10%。
这段代码运行良好:
function site_wide_shop_discount_with_custom_title( $cart ) {
$discount = $cart->subtotal * 0.1;
$cart->add_fee( __( 'YOUR TEXT HERE', 'your-text-domain' ) , -$discount );
}
add_action( 'woocommerce_cart_calculate_fees', 'site_wide_shop_discount_with_custom_title' );
我的目标是将其限制在一个日期范围内和 100 个订单。这段代码是我的目标,但它不起作用:
function shop_discount_for_100_orders( $cart ) {
$discountWeekStart = new DateTime('2018-10-07'); // when the discount week starts
$dsicountWeekEnd = new DateTime('2018-10-15'); // when the discount week ends
$hundred_orders_discount = $cart->subtotal * 0.1; // during discount week, we give ten percent off the cart subtotal
$hundred_orders_discount_over = $cart->subtotal; // no more discount
if ( $discountWeekStart ) {
$cart->add_fee( __( 'Global Discount Week', 'my-text-domain' ) , -$hundred_orders_discount );
} else if {
$hundred_orders_discount_over;
}
}
add_action( 'woocommerce_cart_calculate_fees', 'shop_discount_for_100_orders' );
关于如何将折扣限制在某个日期范围内以及如何将其设置为从最后一个订单开始计算的 100 个订单有什么想法吗?
感谢任何想法、帮助或支持。
【问题讨论】:
标签: php wordpress woocommerce cart discount