• Dear friends at Haste,

    Is there a way to make delivery time field not required? I’m trying to achieve it with this code, but it doesn’t work:

    
    function make_delivery_time_not_required( $address_fields ) {
         $address_fields['delivery_time']['required'] = false;
         return $address_fields;
    }
    add_filter( 'woocommerce_checkout_fields' , 'make_delivery_time_not_required' );
    

    Thanks in advance,
    Marco Andrei

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Allyson

    (@allysonsouza)

    Hi Marco,

    The easiest way I though you could do that is unregistering the hook where we create the fields in the plugin, and then recreating it without the required option, like that:

    
    remove_action( 'woocommerce_before_order_notes', 'delivery_date_system_echo_fields', 5 );
    
    function delivery_date_system_echo_non_required_fields( $checkout ) {
    	echo '<div class="delivery-options">';
    	
    	woocommerce_form_field( 'delivery_date', array(
    		'type'          => 'text',
    		'class'         => array('form-row-wide'),
    		'id'            => 'datepicker',
    		'required'      => false,
    		'label'         => __( 'Select one of the available delivery days', 'delivery-date-system' ),
    		'placeholder'   => __( 'Open calendar', 'delivery-date-system' ),
    		'autocomplete'  => 'off',
    	));
    	
    	if ( ! empty( delivery_time_options() ) ) {
    		woocommerce_form_field( 'delivery_time', array(
    			'type'          => 'select',
    			'class'         => array('form-row-wide'),
    			'id'            => 'delivery-time',
    			'required'      => false,
    			'label'         => __( 'Select a delivery time', 'delivery-date-system' ),
    			'options'     	=> delivery_time_options()
    		));
    	}
    		
    	echo '</div>';
    }
    add_action( 'woocommerce_before_order_notes', 'delivery_date_system_echo_non_required_fields', 5 );
    

    I hope this can help you!

    Best regards,
    Allyson Souza

    • This reply was modified 5 years, 7 months ago by Allyson.
    • This reply was modified 5 years, 7 months ago by Allyson.
    Plugin Contributor Allyson

    (@allysonsouza)

    Hi @marcoandrei, it’s been a while since we get from you, any updates on this issue? The snippet helped you?

    Thanks!

    ola Allison,
    Como posso desativar o calendário, só quero a op??o de escolher horário

    desde já agrade?o.

    Plugin Contributor Allyson

    (@allysonsouza)

    Olá @kensuke3k,

    Infelizmente no momento n?o há op??es para desativar o calendário, mas é um ótima ideia para uma vers?o futura. Se você tiver conhecimentos de programa??o, é possível remover os hooks que registram e validam os campos e recria-los em seu functions.php sem campo de data:

    function delivery_date_system_echo_fields_without_calendar( $checkout ) {
    	echo '<div class="delivery-options">';
    	
    	if ( ! empty( delivery_time_options() ) ) {
    		woocommerce_form_field( 'delivery_time', array(
    			'type'          => 'select',
    			'class'         => array('form-row-wide'),
    			'id'            => 'delivery-time',
    			'required'      => true,
    			'label'         => __( 'Select a delivery time', 'delivery-date-system' ),
    			'options'     	=> delivery_time_options()
    		));
    	}
    		
    	echo '</div>';
    }
    remove_action( 'woocommerce_before_order_notes', 'delivery_date_system_echo_fields', 5 );
    add_action( 'woocommerce_before_order_notes', 'delivery_date_system_echo_fields_without_calendar', 5 );
    
    function delivery_date_system_validate_new_checkout_fields_without_calendar() {
    	if ( empty( $_POST['delivery_time'] ) ) wc_add_notice( __( 'Select an available delivery time.', 'delivery-date-system' ), 'error' );
    }
    remove_action( 'woocommerce_checkout_process', 'delivery_date_system_validate_new_checkout_fields' );
    add_action( 'woocommerce_checkout_process', 'delivery_date_system_validate_new_checkout_fields_without_calendar' );

    Agrade?o a compreens?o

    Olá @allysonsouza
    funciono, mto obrigado.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Make delivery time field not required’ is closed to new replies.