Hide times when time has passed in custom select field in WooCommerce checkout - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Wednesday, June 9, 2021

Hide times when time has passed in custom select field in WooCommerce checkout

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' ));
}

example


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



source https://stackoverflow.com/questions/67889698/hide-times-when-time-has-passed-in-custom-select-field-in-woocommerce-checkout

No comments:

Post a Comment