Skip to content

Instantly share code, notes, and snippets.

@kloon
Last active December 18, 2021 18:55
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kloon/8593009 to your computer and use it in GitHub Desktop.
Save kloon/8593009 to your computer and use it in GitHub Desktop.
WooCommerce Checkout Field Editor, add date range to datepicker field
<?php
// Add a date range to a datepicker field, replace #date with the id of the date field.
add_filter( 'wp_footer' , 'woo_add_checkout_field_date_range_limit' );
function woo_add_checkout_field_date_range_limit() {
if ( is_checkout() ) {
$js = 'jQuery( "#date" ).datepicker({ minDate: -5, maxDate: "+1M +10D" });';
// Check if WC 2.1+
if ( defined( 'WC_VERSION' ) && WC_VERSION ) {
wc_enqueue_js( $js );
} else {
global $woocommerce;
$woocommerce->add_inline_js( $js );
}
}
}
?>
@cerjach
Copy link

cerjach commented Aug 9, 2018

Hello, I'm trying to set up two datepicker fields, the first one being anytime in the future while the second one being 2 days and more after the date selected in the first field. Any ideas on how this could be achieved are very much appreciated!

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