Adding/Customizing Account and Checkout Billing Fields – WooCommerce

Advertisement

This is another snippet in WooCommerce I’d like to share with you guys, I’ve been working with WooCommerce lately and one of the functionality client requested is to add custom fields in Checkout Billing and have it propagated to My Account page, so user can update and add information in their spare time with ease.

Worry about the save and update hook? WooCoommerce automatically do that for us folks so set back and enjoy, we’re done, and yes that’s easy not as what you’ve expected.

Let’s get started

Parameters


{
	'label'     	=> __('Neck Circumference', 'woocommerce'), 				// field label name
	'placeholder'   => _x('Neck Circumference', 'placeholder', 'woocommerce'), 	// field placeholder
	'required'  	=> false,													// FALSE if not required otherwise set it to TRUE
	'class'     	=> array('form-row-first'), 								// field class available are 'form-row-first', 'form-row-last' and 'form-row-wide'
	'clear'     	=> false													// TRUE if you'd like to add clear DIV right after this field
}

Code


// Hook in
add_filter( 'woocommerce_billing_fields', 'rs_custom_billing_fields' );

// Function Hook
Function rs_custom_billing_fields( $fields )  {
	$fields['billing_facebook'] = array(
		'label'     	=> __('Facebook', 'woocommerce'),
		'placeholder'   => _x('Facebook', 'placeholder', 'woocommerce'),
		'required'  	=> false,
		'class'     	=> array('form-row-first'),
		'clear'     	=> false
    );

	$fields['billing_twitter'] = array(
		'label'     	=> __('Twitter', 'woocommerce'),
		'placeholder'   => _x('Twitter', 'placeholder', 'woocommerce'),
		'required'  	=> false,
		'class'     	=> array('form-row-last'),
		'clear'     	=> true
    );

    // just copy same format if you'd like to add more fields

	return $fields;
}

Happy coding ^_^

Advertisement