Advertisement
sparkweb

Sample Code For Datebox on Variation

Aug 13th, 2011
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. //Code to Make a Text Input Box Become a Date Selection Box
  2. //Paste This Code into your functions.php file
  3. function load_datepicker_script() {
  4.     wp_enqueue_script('jquery-ui-core');
  5.     wp_enqueue_style('datepickerStyle', FOXYSHOP_DIR . '/css/ui-smoothness/jquery-ui.custom.css');
  6.     wp_enqueue_script('datepickerScript', FOXYSHOP_DIR . '/js/jquery-ui.datepicker.min.js', array('jquery','jquery-ui-core'));
  7. }
  8. add_action('wp_enqueue_scripts', 'load_datepicker_script');
  9.  
  10. function foxyshop_get_excluded_dates() {
  11.     global $product;
  12.     $excludeDates = get_post_meta($product['id'], 'excludeDates', 1);
  13.     if ($excludeDates) {
  14.         $excludeDates = explode(",", $excludeDates);
  15.         $strDisabledDays = "[";
  16.         foreach($excludeDates AS $val) {
  17.                if ($strDisabledDays != "[") $strDisabledDays .= ", ";
  18.                $strDisabledDays .= '"' . trim(date("n-j-Y", strtotime($val))) . '"';
  19.         }
  20.         $strDisabledDays .= "];";
  21.     } else {
  22.         $strDisabledDays = "[];";
  23.     }
  24.     echo $strDisabledDays;
  25. }
  26.  
  27. //To constrain calender, use custom fields minDate, maxDate, and excludeDates
  28. //By default minDate will allow nothing before the current date (0)
  29. function foxyshop_get_min_max_date() {
  30.     global $product;
  31.     $minDate = get_post_meta($product['id'], 'minDate', 1);
  32.     $maxDate = get_post_meta($product['id'], 'maxDate', 1);
  33.     if ($minDate != '') {
  34.         $minDate = (strpos("/", $minDate) !== false ? "new Date(" . date('F j, Y', strtotime($minDate)) . ")" : "'$minDate'");
  35.     } else {
  36.         $minDate = 0;
  37.     }
  38.     if ($maxDate != '') {
  39.         $maxDate = (strpos("/", $maxDate) !== false ? "new Date(" . date('F j, Y', strtotime($maxDate)) . ")" : "'$maxDate'");
  40.     }
  41.     echo ",minDate: $minDate\n";
  42.     if ($maxDate != "") echo ",maxDate: $maxDate\n";
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement