title: Disable specific dates and enable specific days of the week in jQuery datepicker
body: <p>I'm trying to disable specific dates and enable only specific days of the week on a jQuery UI datepicker.</p>
  
  <p>This is inside a Wordpress/Woocommerce theme and I'm trying to solve some bugs but I'm here for hours trying to figure out for a solution and even tried every solution I found on StackOverflow and other websites, but nothing seems to work.</p>
  
  <p>My objective is to enable only chosen days of the week to be available, but when a date is chosen and bought, I need to disable it too. I successfully disabled the days of the week that I need to be disabled, but I can't do even a hardcoded prototype about the bought dates that should be disabled.</p>
  
  <p>The code (with some hardcoded sample): </p>
  
  <pre><code>$(document).ready(function(){
      var available_days = ["3"]; //it comes from the database
      var today = new Date();
      var tour_start_date = new Date( 1525132800000 ); //it comes from the database
      var tour_end_date = new Date( 1546214400000 ); //it comes from the database
      var available_first_date = tour_end_date;
      var lang = 'en_UK';
  
      lang = lang.replace( '_', '-' );
  
      today.setHours(0, 0, 0, 0);
      tour_start_date.setHours(0, 0, 0, 0);
      tour_end_date.setHours(0, 0, 0, 0);
  
      if ( today &gt; tour_start_date ) {
          tour_start_date = today;
      }
  
      function DisableDays(date) {
          var day = date.getDay();
  
          if ( available_days.length == 0 ) {
              if ( available_first_date &gt;= date &amp;&amp; date &gt;= tour_start_date) {
                  available_first_date = date;
              }
              return true;
          }
  
          if ( $.inArray( day.toString(), available_days ) &gt;= 0 ) {
              if ( available_first_date &gt;= date &amp;&amp; date &gt;= tour_start_date) {
                  available_first_date = date;
              }
              return true;
          } else {
              return false;
          }
      }
      if ( $('input.date-pick').length ) {
          if ( lang.substring( 0, 2 ) != 'fa' ) {
              $('input.date-pick').datepicker({
                  startDate: tour_start_date,
                  endDate: tour_end_date,
                  beforeShowDay: DisableDays,
                  language: lang
              });
              $('input[name="date"]').datepicker( 'setDate', available_first_date );
          } else {
              var date_format = $('input.date-pick').data('date-format');
              $('input.date-pick').persianDatepicker({
                  observer: true,
                  format: date_format.toUpperCase(),
              });
          }
      }
  });
  </code></pre>