Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jessepearson/1db1b699c8bb2fc0207cbfd178d0d797 to your computer and use it in GitHub Desktop.
Save jessepearson/1db1b699c8bb2fc0207cbfd178d0d797 to your computer and use it in GitHub Desktop.
By default the current month will be shown on the WooCommerce Bookings calendar for performance reasons. This will default it to the month with the first available block.
<?php // do not copy this line
/**
* Will make the Bookings calender default to the month with the first available booking.
*/
add_filter( 'wc_bookings_calendar_default_to_current_date', '__return_false' );
@afnanabbasi
Copy link

This helped. Thanks !

@pares90
Copy link

pares90 commented Jun 5, 2020

Is there a way to make this work in order to automatically select the first available time when picked a date?

@jessepearson
Copy link
Author

@pares90 That would take additional JavaScript loaded via other means to select the first day and/or time.

@diegobril
Copy link

Is there a way to make this work in order to automatically select the first available time when picked a date?

paste this on your theme's javascript file
//select the first available date of the calendar
function loadFrame() {
let availableDate = document.querySelectorAll(".single-product a.ui-state-default");
if ( document.contains(availableDate[0]) ) {
availableDate[0].click();
}
}
window.onload = setTimeout(loadFrame, 3000);

it will click on the first available date, 3 seconds after the page finishes to load

@masterfugazi
Copy link

Why doesn't this work? add_filter( 'wc_bookings_calendar_default_to_current_date', '__return_false' );

-I've added the code both ways with a custom function and without, in my child themes funtions.php folder...Nothing.

Anything else I should try would love to get this working, as it's kinda a convent feature to have when events aren't in the current month.

@liammcluckie
Copy link

I have been using this filter to set the calendar to show the first available date using version 1.16 of WooCommerce bookings. I recently updated to the latest version 2.0.3 and this no longer works. I have rolled the plugin version back and it starts working correctly again.

@jessepearson
Copy link
Author

@liammcluckie I do no directly control the code for the Bookings plugin, if you are having an issue with it, I would recommend reaching out to support at WooCommerce.com.

For what it's worth, I did check Bookings and the filter still exists, so if it's not working support should be notified.

@liammcluckie
Copy link

@jessepearson Thanks for the reply. Apologies for adding this here, for some reason I thought this thread was part of the plugin repo! I will get a ticket open with support. Cheers

@tfrank77
Copy link

I have the same problem here, after 2 years of usage. Very odd.

@liammcluckie
Copy link

@tfrank77 Just to let you know I have contacted WooCommerce support and they have replicated the bug. Their developers have been notified and are working on a fix. They have recommended rolling back to the previous version until this is patched

@tfrank77
Copy link

Just to let you know I have contacted WooCommerce
Brilliant news, thank you @liammcluckie.

@fscriven
Copy link

From woo: The filter was working on version 2.0.2 and stopped working when version 2.0.3 was released. Support sent me version 2.0.2 not sure if there is an official download source for old versions.

@jessepearson
Copy link
Author

@fscriven You can reach out to Woo support for a copy of the older version. They have an issue open for the bug, the issue number is 3695.

@tfrank77
Copy link

Thanks guys for the info!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment