Support » Plugin: Delivery Date System for WooCommerce » Make delivery time field not required

  • 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 1 replies (of 1 total)
  • Plugin Contributor Allyson Souza

    (@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

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.