Last active
June 10, 2024 07:31
-
-
Save thisissandip/4de751cdadc05666ccec6cb65aab837c to your computer and use it in GitHub Desktop.
Auto Select the first available booking date in WooCommerce Booking Calendar
This file contains hidden or 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
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