Skip to content

Instantly share code, notes, and snippets.

@thisissandip
Last active June 10, 2024 07:31
Show Gist options
  • Save thisissandip/4de751cdadc05666ccec6cb65aab837c to your computer and use it in GitHub Desktop.
Save thisissandip/4de751cdadc05666ccec6cb65aab837c to your computer and use it in GitHub Desktop.
Auto Select the first available booking date in WooCommerce Booking Calendar
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']");
console.log(datetobeselected);
if(datetobeselected){
clearInterval(interval);
datetobeselected?.click();
}
}
</script>
<?php
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment