Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jessepearson/ac576fda1a4c9c9c898c8810c5bc1ef3 to your computer and use it in GitHub Desktop.
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.
<?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 );
@ZaheerAbbasAghani
Copy link

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