WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
[resolved] Making State field a not required field (3 posts)

  1. Pradeep
    Member
    Posted 1 year ago #

    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/

  2. qrmiz
    Member
    Posted 1 year ago #

    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;
    }
  3. Pradeep
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic