Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Changing fields from WooCommerce checkout WordPress

Hi,

I would like the make the following changes to my WooCommerce checkout fields:

I would like to <strong>remove</strong> the following fields:
Order Notes
Company Name
Phone Number

I would like to make the following fields <strong>not required</strong> to fill out:
Address
Postcode / Zip
Town / City

I would like to make the following fields <strong>required</strong> to fill out:
(If user is not already logged in)
Username
Password

Details from WooCommerce on how to change custom fields is here:
http://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/

My sites checkout can be found here:
http://novelconcept.org/checkout/

Answers (2)

2013-06-23

Dbranes answers:

You could try this:

add_filter( 'woocommerce_checkout_fields' , 'customize_fields' );

function customize_fields( $fields ) {

// remove fields:
unset($fields['order']['order_comments']);
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_phone']);

// make fields not required:
$fields['billing']['billing_address_1']['required'] = false;
$fields['billing']['billing_address_2']['required'] = false;
$fields['billing']['billing_postcode']['required'] = false;
$fields['billing']['billing_city']['required'] = false;

// make fields required:
$fields['account']['account_username']['required'] = true;
$fields['account']['account_password']['required'] = true;
$fields['account']['account_password-2']['required'] = true;

return $fields;
}

this seems to work on my install.


philipzeplin comments:

Removing the fields work just fine, but the remaining fields are still required :(


Dbranes comments:

Hi, have you tried to submit the form and see what happens?

(I still got the star on some of those not-required fields)


Dbranes comments:

ps: You can debug it with

add_filter( 'woocommerce_checkout_fields' , 'customize_fields' );

function customize_fields( $fields ) {
printf( "<!-- %s -->", print_r( $fields, true ) ) ;
return $fields;
}


to see all the fields info, by viewing the page HTML source.


philipzeplin comments:

I haven't tried submitting, no. But that's a bit besides the point, since I'm making it not required to make it easier to register for the user - even if it's not required, if they THINK it is (because of the little red stars), it loses the point :(


Dbranes comments:

There is a Javascript file

/woocommerce/assets/js/frontend/checkout.min.js

that might be adding the extra required star on some checkout-fields:

var required = ' <abbr class="required" title="' + woocommerce_params.i18n_required_text + '">*</abbr>';

It seems to depend on the locale settings from the country dropdown.

I was able to overwrite the default locale settings for France (FR) like this:


add_filter( 'woocommerce_get_country_locale', 'woocommerce_get_country_locale_callback' );

function woocommerce_get_country_locale_callback($locale) {

$locale['FR']['city']['required'] = false;
$locale['FR']['post_code']['required'] = false;
$locale['FR']['address_1']['required'] = false;
$locale['FR']['address_2']['required'] = false;

return $locale;
}


ps:

The un-compressed version is:

/woocommerce/assets/js/frontend/checkout.js


Dbranes comments:

... and if you want to overwrite all the locale settings, you can use:

add_filter( 'woocommerce_get_country_locale_base', 'woocommerce_get_country_locale_base_callback' );
function woocommerce_get_country_locale_base_callback($base) {
//$base['first_name']['required'] = false;
//$base['last_name']['required'] = false;
//$base['state']['required'] = false;
$base['city']['required'] = false;
$base['postcode']['required'] = false;
$base['address_1']['required'] = false;
$base['address_2']['required'] = false;
return $base;
}


it looks like this will take care of the Javascript part.

2013-06-23

Hariprasad Vijayan answers:

Hello,

Try the following plugin

http://wordpress.org/plugins/woocommerce-checkout-manager/


philipzeplin comments:

Sadly the plugin seems to bug up other stuff on the page :(