Weekday coupon restriction in combination with Pinpoint Booking
-
Hi there,
I am in the process of helping a small leisure rental company with an issue regarding coupons in conjunction with a booking from Pinpoint.
They would like to create coupons valid only for bookings on weekdays (Monday/Thursday).
A Pinpoint booking will continue to be handled as a Woocommerce product. So are the coupons.
Pinpoint support has provided me the code to get it to work, but now no other coupon codes are accepted (not in weekdays OR weekends).
Can you maybe help me out?
This is the given code:{ // Set the coupon codes you want to restrict to weekdays $coupon_codes = array('couponcode', 'anothercode', 'thirdcode'); $coupon_code = strtolower($coupon->get_code()); $found = false; // Loop through cart items to check if the coupon code matches and the date is a weekday foreach (WC()->cart->get_cart() as $cart_item) { global $wpdb; global $DOPBSPWooCommerce; $reservations_data = $wpdb->get_results($wpdb->prepare('SELECT * FROM '.$DOPBSPWooCommerce->tables->woocommerce.' WHERE cart_item_key="%s" AND token="%s"', $cart_item['key'], $cart_item['dopbsp_token'])); foreach ($reservations_data as $reservation_data){ $data = json_decode($reservation_data->data); if (in_array($coupon_code, $coupon_codes)) { $the_day = date('D', strtotime($data->check_in)); error_log( print_r( $the_day, true )); if (in_array($the_day, array('Mon', 'Tue', 'Wed', 'Thu'))) { $found = true; break; // No need to continue checking once we find a matching weekday } } } } // If the coupon code is not valid for weekdays, set it as invalid if (!$found) { $valid = false; } return $valid; }
As said, this code works for restricting given coupon codes in the array, but ALL other coupon codes are invalid with this code.
I appreciate your help, thanks in advance.The page I need help with: [log in to see the link]
- The topic ‘Weekday coupon restriction in combination with Pinpoint Booking’ is closed to new replies.