I'm trying to make a function that sets a cart discount of 10% no matter what product or how many that are in the cart.
This code works fine:
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' );
My goal is to limit this to a date range and to 100 orders. This code, which is my goal, does not work:
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' );
Any ideas on how to limit the discount to a date range and how to set it to 100 orders counting from the last one?
Any ideas, help or support is appreciated.