Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jessepearson/1db1b699c8bb2fc0207cbfd178d0d797 to your computer and use it in GitHub Desktop.

Select an option

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' );
@seffect

seffect commented Apr 26, 2018

Copy link
Copy Markdown

This is not working in my case, I have it on a duplicate site with all other plugins disabled and the 2017 theme and still doesn't work, only tested on mac but all three browsers exhibit the same behavior, always shows the current month, plus the default min lead time. It used to work then a bookings plugin update ruined it, support hasn't been able to help yet. Digging into the code and forcing the state this filter invokes does nothing as well. Just wanted to let people know it might not always work, if at all.

@RexAK

RexAK commented Jul 24, 2018

Copy link
Copy Markdown

Wanted to report that it works correctly for me if I use a custom function, as opposed to the shorthand above. Is in:

add_filter( 'wc_bookings_calendar_default_to_current_date', 'your_prefix_wc_bookings_calendar_default_to_current_date', 99 );

    function your_prefix_wc_bookings_calendar_default_to_current_date(){

	    return false;

    }

@AkremBelkahla

AkremBelkahla commented Oct 25, 2018

Copy link
Copy Markdown

If i add this function, all dates are shown not bookable by default. I have to select a date to correct that.
On page load :
annotation
After date selection
annotation
Any idea why and how to fix it ?

@afnanabbasi

Copy link
Copy Markdown

This helped. Thanks !

@pares90

pares90 commented Jun 5, 2020

Copy link
Copy Markdown

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

@jessepearson

Copy link
Copy Markdown
Author

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

@diegobril

Copy link
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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
Copy Markdown
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
Copy Markdown

@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

@tfrank7

tfrank7 commented Sep 27, 2023

Copy link
Copy Markdown

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

@liammcluckie

Copy link
Copy Markdown

@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

@tfrank7

tfrank7 commented Sep 29, 2023

Copy link
Copy Markdown

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

@fscriven

Copy link
Copy Markdown

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
Copy Markdown
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.

@tfrank7

tfrank7 commented Oct 31, 2023

Copy link
Copy Markdown

Thanks guys for the info!

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