This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Cross-Resource Booking Blocker | |
| * | |
| * When a booking is paid using one resource, block the related resources | |
| * to prevent double-booking of shared spaces. | |
| */ | |
| // Define the resource relationships (update these IDs after creating resources) | |
| define('PRIMARY_RESOURCE_ID', 123); // Replace with actual resource ID (e.g., Entire Space) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Replace existing booking in cart with new one | |
| * | |
| * When a customer adds a new booking for a specific bookable product, | |
| * any existing booking for the same product is automatically removed. | |
| * This ensures cross-resource blocking works correctly since it triggers on payment. | |
| */ | |
| // Define the bookable product ID (update after creating the product) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Booking Date-Based Coupon Rules | |
| * | |
| * Define which coupons are valid for which booking date ranges. | |
| * Just edit the $coupon_rules array below. | |
| */ | |
| add_filter( 'woocommerce_coupon_is_valid', function( $valid, $coupon, $discount ) { | |
| if ( ! $valid || ! WC()->cart ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function wccr_add_roles_snippet() { | |
| // Uncomment these "Remove" lines ONCE if you change capabilities below and need to refresh the roles. | |
| // remove_role( 'fulfilment_operator' ); | |
| // remove_role( 'store_operator' ); | |
| // 1. Fulfilment Operator | |
| add_role( | |
| 'fulfilment_operator', | |
| __( 'Fulfilment Operator', 'woocommerce' ), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Cancel WooCommerce Bookings when an order status changes from Pending to Failed. | |
| */ | |
| add_action('woocommerce_order_status_changed', 'wc_cancel_bookings_on_failed_order', 10, 4); | |
| function wc_cancel_bookings_on_failed_order($order_id, $from_status, $to_status, $order) { | |
| // Check if the transition is from 'pending' to 'failed' | |
| if ($from_status === 'pending' && $to_status === 'failed') { | |
| // Ensure the Bookings classes exist |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_action('admin_init', function () { | |
| $role = get_role('administrator'); | |
| if (!$role) { | |
| return; | |
| } | |
| // Core Bookings capabilities | |
| $caps = array( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| Add a 1-hour buffer period to resource availability AFTER a paid booking ends by blocking availability | |
| from the booking's end time to 1 hour later. This prevents back-to-back bookings. | |
| */ | |
| function auto_create_one_hour_buffer_availability_resource($booking_id) { | |
| $booking = new WC_Booking($booking_id); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Monitor new booking creation using wc_get_logger | |
| */ | |
| function log_all_new_bookings( $booking_id ) { | |
| if ( ! function_exists( 'get_wc_booking' ) ) { | |
| return; | |
| } | |
| $booking = get_wc_booking( $booking_id ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_action( 'wp_footer', 'bookable_product_script_js'); | |
| function bookable_product_script_js() { | |
| global $product; | |
| // Only on single bookable products | |
| if( is_product() && $product->is_type('booking')) : | |
| ?> | |
| <script type='text/javascript'> | |
| var interval = setInterval(checkifDateisLoaded, 500); // set booking calendar load time | |
| function checkifDateisLoaded() { | |
| const datetobeselected = document.querySelector("[title='This date is available']"); |
NewerOlder