Hi @franckeg!
WooCommerce’s woocommerce_form_field()
function is a wrapper for creating form fields in WooCommerce settings and forms, and it doesn’t inherently provide options for setting the minimum and maximum dates for date fields. However, you can achieve this functionality by using HTML attributes directly in the field markup.
Here’s an example of how you can create a date field with minimum and maximum date attributes using woocommerce_form_field()
:
woocommerce_form_field(
'custom_date_field',
array(
'type' => 'date',
'label' => 'Select a Date',
'required' => true,
'class' => array('form-row-wide'),
'custom_attributes' => array(
'min' => date('Y-m-d'), // Set minimum date to today
'max' => date('Y-m-d', strtotime('+1 year')) // Set maximum date to one year from today
)
)
);
Please note that this is just an example. Otherwise, feel free to share more details about what you are trying to achieve and we are happy to take a closer look.
Thank you!