John Davidson

php - Add a custom select field with collection times in WooCommerce checkout

0 comments
Message:


I have created a custom checkout field for collection times on my website (see image attached)


This is my current code:


add_action('woocommerce_before_order_notes', 'njengah_add_select_checkout_field');
function njengah_add_select_checkout_field( $checkout ) {
woocommerce_form_field( 'daypart', array(
'type' => 'select',
'class' => array( 'njengah-drop' ),
'label' => __( 'Collection Time' ),
'required' => true,
'options' => array(
'blank' => __( 'Select a collection time', 'njengah' ),
'5:00_PM' => __( '5:00 PM', 'njengah' ),
'5:30_PM' => __( '5:30 PM', 'njengah' ),
'6:00_PM' => __( '6:00 PM', 'njengah' ),
'6:30_PM' => __( '6:30 PM', 'njengah' ),
'7:00_PM' => __( '7:00 PM', 'njengah' ),
'7:30_PM' => __( '7:30 PM', 'njengah' ),
'8:00_PM' => __( '8:00 PM', 'njengah' )
)
), $checkout->get_value( 'daypart' ));
}




However, the intention is to hide collection times when time has passed


E.G. - If its 6pm hide: 5:00 PM and 5:30 PM


Any help would be great



My Answer:
> 'select',
> 'class' => array('form-row-wide'),
> 'label' => __('Select Collection Time'),
> 'required' => true,
> 'options' => array(
> 'morning' => __('Morning (9am - 12pm)'),
> 'afternoon' => __('Afternoon (1pm - 5pm)'),
> 'evening' => __('Evening (6pm - 9pm)')
> )
> );

You can add this code to your functions.php file in your theme or child theme to display the custom select field on the WooCommerce checkout page. This code will create a select field with options for morning, afternoon, and evening collection times. You can customize the options and labels as needed for your specific requirements.

Rate this post

4 of 5 based on 9683 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us