dqfaom241360
2017-01-04 12:46
浏览 48
已采纳

在woocommerce结帐页面自定义字段中添加日期

I am trying to add custom select option in woocommerce checkout page. It is adding the extra field but I want to add the date in the value of the select option.

Is there any solution for this?

Here is the code I added in my theme function.php

$today = new DateTime();
$tomorrow = new DateTime();
$tomorrow->modify('+1 day');
$dayAfterTomorrow = new DateTime();
$dayAfterTomorrow->modify('+2 day');

add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );

function my_custom_checkout_field( $checkout ) {
    echo '<div id="my_custom_checkout_field"><h2>' . __('My Field') . '</h2>';

    woocommerce_form_field( 'my_field_name', array(
        'type'          => 'select',
        'class'         => array('my-field-class form-row-wide'),
        'label'         => __('Fill in this field'),
        'placeholder'   => __(''),
        'options'     => array(
          'Today' => __("This should be today's date"),
          'Tomorrow' => __('This should be tomorrow date'),
          'Day After Tomorrow' => __('This should be Day After Tomorrow Date')
        )), $checkout->get_value( 'my_field_name' ));
    echo '</div>';
}
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题