Last active
August 7, 2023 14:48
-
-
Save jessepearson/ac576fda1a4c9c9c898c8810c5bc1ef3 to your computer and use it in GitHub Desktop.
Make it so that all time slots in a time-based booking in WooCommerce Bookings shows how many spots remain, not just partially booked blocks.
This file contains 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 // do not copy this line | |
function rewrite_wc_bookings_get_time_slots_html( $block_html, $available_blocks, $blocks ) { | |
$block_html = ''; | |
foreach ( $available_blocks as $block => $quantity ) { | |
if ( $quantity['available'] > 0 ) { | |
$block_html .= '<li class="block" data-block="' . esc_attr( date( 'Hi', $block ) ) . '"><a href="#" data-value="' . date( 'c', $block ) . '">' . date_i18n( get_option( 'time_format' ), $block ) . ' <small class="booking-spaces-left">(' . sprintf( _n( '%d left', '%d left', $quantity['available'], 'woocommerce-bookings' ), absint( $quantity['available'] ) ) . ')</small></a></li>'; | |
} | |
} | |
return $block_html; | |
} | |
add_filter( 'wc_bookings_get_time_slots_html', 'rewrite_wc_bookings_get_time_slots_html', 10, 3 ); |
@iceryan354 There should be an option on the General tab in the product itself. If you run into issues, reach out to support through your account at WooCommerce.com and they will be able to help you out.
Hi jesse is there any function to find booked time slot for a particular date
HI there,
I want to show the booking price below each date in the calendar.
I used the above code but nothing is showing.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks Jesse - related issue: any way to have the booking calender by default on load, display the current highlighted days timeslots? Seems to always require an initial click... Great work and cheers.