0

In this location in wordpress

/wp-includes/js/jquery/ui

there is a file jquery.ui.datepicker.js

I need to override this bit of code

    noWeekends: function(date) {
            var day = date.getDay();
            return [(day > 0 && day < 6), ''];
    },

to make it only show wednesdays (day > 2 && day < 4). Obviously I don't want to do it in the file itself as it will get overridden. I tried a few things I've found online in the header, but it doesn't seem to be working.

Looking for either a code for the header, or the function file.

1

I haven't tested this, but this should work and don't forget to replace the jQuery selector with your own:

$(function() {
 if(typeof jQuery.datepicker === 'function'){
    $( ".your_date_picker_field_selector" ).datepicker({
        beforeShowDay: function (t) {
            var e = t.getDay();
            return [e == 3, ""]
        }
    });
  }
});

Updated: Since, you are using contact form 7 datepicker addon, use filter to customize the meeting date field js.

add_filter( 'cf7dp_datepicker_javascript', 'custom_date_picker_js', 10, 2 );

function custom_date_picker_js( $out, $field ) {
       // Target only the meeting date field.
       if ( $field->type != 'datepicker' || $field->input_name != 'date-553' ) {
            return $out;
    }

    $out .= ".datepicker('option', 'beforeShowDay', function (t) {
        var e = t.getDay();
        return [e == 3, \"\"]
    })";
    $out .= ".datepicker('refresh');";

    return $out;
}
4
  • I did remember to change the selector, but I am getting a "TypeError: $(...).datepicker is not a function $( "#ui-datepicker-div" ).datepicker({"
    – KVDD
    Feb 6 '15 at 20:26
  • Enqueue the datepicker js wp_enqueue_script('jquery-ui-datepicker'); Feb 6 '15 at 20:31
  • I've enqueued the script in my functions file, but still get the same error. I don't know if a link to my site would be helpful or not: bnidynamo.com/guest-registration
    – KVDD
    Feb 6 '15 at 21:38
  • Check the updated answer. It should work. Feb 7 '15 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.