Datepicker – blockout weekends and specific days

Home Forums Quform WordPress Datepicker – blockout weekends and specific days

This topic is: resolved
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2153
    kbrands
    Participant

    Hi

    I am trying to blockout all weekends and public holidays (specific dates) in the datepicker. I have reviewed and applied the code offered here https://support.themecatcher.net/quform-wordpress/guides/advanced/date-validation however my problem is I can get either all weekends bolcked out OR the specific dates I have specified but I can’t get both working together.

    I did notice that the last paragraph under “Prevent specific dates from being chosen” it states:
    “Note that the datepicker options hooks will not inherit the options from any previous hooks. So if you plan on using both steps above to block past dates and specific dates, you should move the datepicker options into one function.”

    Is this the same for what I am trying to do – all weekends + specific days/dates? If so, could you advise how I would combine these into one function as I am unsure how.

    Your help would be greatly appreciated.

    Thank You! K

    #2158
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #2314
    kbrands
    Participant

    Thank you for your reply. I apologise for the delay in mine…changed hosts and lost access for a few days. I tried adding the code you provided but I fear I have not put it in the right spot as the specific days are blocked out but not the weekends 🙁 I have included the full function code I currently have below…I would appreciate it if you could advise how I should be structuring it as I find myself a bit clueless at this point… Thank you!

    function mytheme_get_dates_to_disable()
    {
    return array(
    ‘2013-1-26’,
    ‘2013-1-28’,
    ‘2013-3-29’,
    ‘2013-4-1’,
    ‘2013-4-25’,
    ‘2013-6-10’,
    ‘2013-7-10’,
    ‘2013-12-25’,
    ‘2013-12-26’,
    ‘2014-1-1’,
    ‘2014-1-27’,
    ‘2014-4-1’,
    ‘2014-4-18’,
    ‘2014-4-21’,
    ‘2014-4-25’,
    ‘2014-6-9’,
    ‘2014-10-6’,
    ‘2014-12-25’,
    ‘2014-12-26’,
    ‘2015-1-1’,
    ‘2015-1-26’,
    ‘2015-4-3’,
    ‘2015-4-6’,
    ‘2015-6-8’,
    ‘2015-10-5’,
    ‘2015-12-25’,
    ‘2015-12-28’,
    ‘2016-1-1’,
    ‘2016-1-26’,
    ‘2016-3-25’,
    ‘2016-3-28’,
    ‘2016-4-25’,
    ‘2016-6-13’,
    ‘2016-10-3’,
    ‘2016-12-26’,
    ‘2016-12-27’
    );
    }

    function mytheme_prevent_specific_dates($valid, $value, $element)
    {
    if ($valid) {
    $disabledDates = mytheme_get_dates_to_disable();
    $submittedDate = “{$value[‘year’]}-{$value[‘month’]}-{$value[‘day’]}”;

    if (in_array($submittedDate, $disabledDates)) {
    $element->addError(‘That date is not available’);
    $valid = false;
    }
    }

    return $valid;
    }
    add_filter(‘iphorm_element_valid_iphorm_1_23’, ‘mytheme_prevent_specific_dates’, 10, 3);

    function mytheme_datepicker_prevent_specific_dates($options, $dpMinYear, $dpMaxYear, $element)
    {
    return “{
    beforeShowDay: function (date) {
    if (quformDisabledDates) {
    for (var i = 0; i

    var quformDisabledDates = ;

    <?php
    }
    add_action('wp_head', 'mytheme_print_dates_to_disable');
    return "{
    beforeShowDay: function (date) {
    if (quformDisabledDates) {
    for (var i = 0; i < quformDisabledDates.length; i++) {
    var parts = quformDisabledDates[i].split('-');
    if (date.getFullYear() == parts[0] && (date.getMonth()+1) == parts[1] && date.getDate() == parts[2]) {
    return [false];
    }
    }
    }

    var day = date.getDay();
    if (day == 0 || day == 6) {
    // It's a Sunday or Saturday, block the date
    return [false, ''];
    } else {
    return [true, ''];
    }
    }
    }";

    #2319
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #2321
    kbrands
    Participant

    Here it is…sorry…I’m a bit of a newb 🙂


    function mytheme_get_dates_to_disable()
    {
    return array(
    '2013-1-26',
    '2013-1-28',
    '2013-3-29',
    '2013-4-1',
    '2013-4-25',
    '2013-6-10',
    '2013-7-10',
    '2013-12-25',
    '2013-12-26',
    '2014-1-1',
    '2014-1-27',
    '2014-4-1',
    '2014-4-18',
    '2014-4-21',
    '2014-4-25',
    '2014-6-9',
    '2014-10-6',
    '2014-12-25',
    '2014-12-26',
    '2015-1-1',
    '2015-1-26',
    '2015-4-3',
    '2015-4-6',
    '2015-6-8',
    '2015-10-5',
    '2015-12-25',
    '2015-12-28',
    '2016-1-1',
    '2016-1-26',
    '2016-3-25',
    '2016-3-28',
    '2016-4-25',
    '2016-6-13',
    '2016-10-3',
    '2016-12-26',
    '2016-12-27'
    );
    }

    function mytheme_prevent_specific_dates($valid, $value, $element)
    {
    if ($valid) {
    $disabledDates = mytheme_get_dates_to_disable();
    $submittedDate = "{$value['year']}-{$value['month']}-{$value['day']}";

    if (in_array($submittedDate, $disabledDates)) {
    $element->addError('That date is not available');
    $valid = false;
    }
    }

    return $valid;
    }
    add_filter('iphorm_element_valid_iphorm_1_23', 'mytheme_prevent_specific_dates', 10, 3);

    function mytheme_datepicker_prevent_specific_dates($options, $dpMinYear, $dpMaxYear, $element)
    {
    return "{
    beforeShowDay: function (date) {
    if (quformDisabledDates) {
    for (var i = 0; i < quformDisabledDates.length; i++) {
    var parts = quformDisabledDates[i].split('-');
    if (date.getFullYear() == parts[0] && (date.getMonth()+1) == parts[1] && date.getDate() == parts[2]) {
    return [false];
    }
    }
    }
    return [true];
    }
    }";
    }
    add_filter('iphorm_datepicker_options_iphorm_1_23', 'mytheme_datepicker_prevent_specific_dates', 10, 4);
    function mytheme_print_dates_to_disable()
    {
    ?>
    <script type="text/javascript">
    var quformDisabledDates = <?php echo json_encode(mytheme_get_dates_to_disable()); ?>;
    </script>
    <?php
    }
    add_action('wp_head', 'mytheme_print_dates_to_disable');

    function mytheme_datepicker_block_days($options, $dpMinYear, $dpMaxYear, $element)
    {
    return "{
    beforeShowDay: function (date) {
    var day = date.getDay();
    if (day == 0 || day == 6) {
    // It's a Sunday or Saturday, block the date
    return [false, ''];
    } else {
    return [true, ''];
    }
    }
    }";
    }
    add_filter('iphorm_datepicker_options_iphorm_1_23', 'mytheme_datepicker_block_days', 10, 4);
    function mytheme_block_days($valid, $value, $element)
    {
    if ($valid) {
    $time = strtotime("{$value['year']}-{$value['month']}-{$value['day']}");
    $day = date('w', $time);

    if ($day == 0 || $day == 6) {
    $element->addError('Please choose another day');
    $valid = false;
    }
    }

    return $valid;
    }
    add_filter('iphorm_element_valid_iphorm_1_23', 'mytheme_block_days', 10, 3);

    #2329
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #2330
    kbrands
    Participant

    Thank you Ally! That code worked a treat!!! 🙂

    #14543
    pik70
    Participant

    Hi,

    I have two forms, in the first form I blocked the thursdays with your code “Blocking entire days”, and it’s work. I need block the wednesday in the second form, when I put again the code in the functions.php, just change the unique ID and the days, doesn’t work and my web show me a error.

    This is my code:

    //FIRST BLOCK//
    function mytheme_datepicker_block_days($options, $dpMinYear, $dpMaxYear, $element)
    {
    return “{
    beforeShowDay: function (date) {
    var day = date.getDay();
    if (day == 0 || day == 1 || day == 2 || day == 3 || day == 5 || day == 6) {
    // Esta fecha no opera este tour.
    return [false, ”];
    } else {
    return [true, ”];
    }
    }
    }”;
    }
    add_filter(‘iphorm_datepicker_options_iphorm_206_64’, ‘mytheme_datepicker_block_days’, 10, 4);

    function mytheme_block_days($valid, $value, $element)
    {
    if ($valid) {
    $time = strtotime(“{$value[‘year’]}-{$value[‘month’]}-{$value[‘day’]}”);
    $day = date(‘w’, $time);

    if (day == 0 || day == 1 || day == 2 || day == 3 || day == 5 || day == 6) {
    $element->addError(‘Este tour tiene salidas los días JUEVES’);
    $valid = false;
    }
    }

    return $valid;
    }
    add_filter(‘iphorm_element_valid_iphorm_206_64’, ‘mytheme_block_days’, 10, 3);

    //SECOND BLOCK//
    function mytheme_datepicker_block_days($options, $dpMinYear, $dpMaxYear, $element)
    {
    return “{
    beforeShowDay: function (date) {
    var day = date.getDay();
    if (day == 0 || day == 1 || day == 2 || day == 4 || day == 5 || day == 6) {
    // Esta fecha no opera este tour.
    return [false, ”];
    } else {
    return [true, ”];
    }
    }
    }”;
    }
    add_filter(‘iphorm_datepicker_options_iphorm_207_64’, ‘mytheme_datepicker_block_days’, 10, 4);

    function mytheme_block_days($valid, $value, $element)
    {
    if ($valid) {
    $time = strtotime(“{$value[‘year’]}-{$value[‘month’]}-{$value[‘day’]}”);
    $day = date(‘w’, $time);

    if (day == 0 || day == 1 || day == 2 || day ==43 || day == 5 || day == 6) {
    $element->addError(‘Este tour tiene salidas los días MIERCOLES’);
    $valid = false;
    }
    }

    return $valid;
    }
    add_filter(‘iphorm_element_valid_iphorm_207_64’, ‘mytheme_block_days’, 10, 3);

    Regards,

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy