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
| /* | |
| This snippet ensures that when a booking is paid for a booking product with multiple resources, | |
| all other linked resources are automatically blocked for the same time slot. It dynamically adds | |
| an availability rule within the booking product blocking the slot, preventing other resources bookings for that slot. | |
| */ | |
| function block_booking_slot_to_prevent_other_resource_bookings_on_payment($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']"); |
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 remove_tab_7252021 ($tabs){ | |
| unset($tabs['bookings_templates']); | |
| return($tabs); | |
| } | |
| add_filter('woocommerce_product_data_tabs', 'remove_tab_7252021', 10, 1); |
NewerOlder