WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Making State field a not required field

[Resolved] Making State field a not required field

  • Pradeep
    Participant

    @pmaheepala

    Could someone explain how to make both shipping and billing State fields non required fields? This is what I tried. It does work but it also adds two blank fields to both billing and shipping address sections

    add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_state', 10, 1 );
    add_filter( 'woocommerce_shipping_fields', 'wc_npr_filter_state', 10, 1 ); 
    
    function wc_npr_filter_state( $address_fields ) {
    	$address_fields['billing_state']['required'] = false;
      $address_fields['shipping_state']['required'] = false;
    	return $address_fields;
    }

    Many thanks in advance.

    http://wordpress.org/extend/plugins/woocommerce/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,

    I was facing this issue, that’s why I found your post…
    It might be too late for an answer, but maybe it will help to someone
    (How to remove state/county as required field)
    Try this code, it helped me:

    add_filter( 'woocommerce_billing_fields', 'custom_woocommerce_billing_fields' );
    
    function custom_woocommerce_billing_fields( $fields ) {
    
       $fields['billing_state']	= array(
          'label'          => __('State/County', 'woothemes'),
          'placeholder'    => __('State/County', 'woothemes'),
          'required'       => false,
          'class'          => array('input-text')
       );
    
     return $fields;
    }
    Pradeep
    Participant

    @pmaheepala

    Hello qrmiz,

    I’ve completely forgotten about this post 🙂 Thanks for the reply. Yes it is a bit late and this is how I achieved it.

    add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_state_billing', 10, 1 );
    add_filter( 'woocommerce_shipping_fields', 'wc_npr_filter_state_shipping', 10, 1 );
    
    function wc_npr_filter_state_billing( $address_fields ) { 
    
    $address_fields['billing_state']['required'] = false;
    return $address_fields;
    }
    function wc_npr_filter_state_shipping( $address_fields ) { 
    
    $address_fields['shipping_state']['required'] = false;
    return $address_fields;
    }

    Let’s hope someone else will find both methods useful.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Making State field a not required field’ is closed to new replies.