dragon8002 2018-03-06 12:15
浏览 76

在Woocommerce结帐中启用自定义日期范围datepicker

I have a checkout field and I want to add date ranges instead of picking a single date. Is it possible to use the snippets from jqueryUI to style it and make it a range of dates? I use this function in Woocommerce checkout page on Wordpress.

Below is my current code in the functions.php where I've added the date.

// Register main datepicker jQuery plugin script
add_action( 'wp_enqueue_scripts', 'enabling_date_picker' );
function enabling_date_picker() {

    // Only on front-end and checkout page
    if( is_admin() || ! is_checkout() ) return;

    // Load the datepicker jQuery-ui plugin script
    wp_enqueue_script( 'jquery-ui-datepicker' );
}

// Call datepicker functionality in your custom text field
add_action('woocommerce_before_order_notes', 'my_custom_checkout_field', 10, 1);
function my_custom_checkout_field( $checkout ) {

    date_default_timezone_set('America/Los_Angeles');
    $mydateoptions = array('' => __('Select PickupDate', 'woocommerce' ));

    echo '<div id="my_custom_checkout_field">
    <h3>'.__('Check In Date').'</h3>';

    echo '
    <script>
        jQuery(function($){
            $("#datepicker").datepicker();
        });
    </script>';

   woocommerce_form_field( 'order_checkin_date', array(
        'type'          => 'text',
        'class'         => array('my-field-class form-row-wide'),
        'id'            => 'datepicker',
        'required'      => true,
        'label'         => __('Check-in Date'),
        'placeholder'       => __('Select Date'),
        'options'     =>   $mydateoptions
        ),$checkout->get_value( 'order_checkin_date' ));

    echo '</div>';
}
  • 写回答

2条回答 默认 最新

  • dphnn333971 2018-03-06 12:37
    关注

    This information is available in the jQueryUI documentation. Here's an example of restricting the user to only allow a date 20 days in the past and 1 month + 20 days into the future. Replace your current $("#datepicker").datepicker(); declaration with the following

    <script>
      jQuery( function() {
        $( "#datepicker" ).datepicker({ minDate: -20, maxDate: "+1M +10D" });
      } );
      </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向