Instantly share code, notes, and snippets.

Embed
What would you like to do?
Customizing WooCommerce checkout fields - Adding custom shipping and billing fields
// Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
$fields['shipping']['shipping_phone'] = array(
'label' => __('Phone', 'woocommerce'),
'placeholder' => _x('Phone', 'placeholder', 'woocommerce'),
'required' => false,
'class' => array('form-row-wide'),
'clear' => true
);
return $fields;
}
/**
* Display field value on the order edit page
*/
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order){
echo '<p><strong>'.__('Phone From Checkout Form').':</strong> ' . get_post_meta( $order->get_id(), '_shipping_phone', true ) . '</p>';
}
@avagp

This comment has been minimized.

Show comment
Hide comment
@avagp

avagp Nov 12, 2016

This snippet breaks my page :/

I dont know what is wrong about it, but if i just paste it, the php crashes

avagp commented Nov 12, 2016

This snippet breaks my page :/

I dont know what is wrong about it, but if i just paste it, the php crashes

@virik

This comment has been minimized.

Show comment
Hide comment
@virik

virik May 15, 2017

I can't get this to work with WooCommerce 3.0. Has WooCommerce changed the way this works lately?

virik commented May 15, 2017

I can't get this to work with WooCommerce 3.0. Has WooCommerce changed the way this works lately?

@hannahswain

This comment has been minimized.

Show comment
Hide comment
@hannahswain

hannahswain Jul 21, 2017

Updated to work with WooCommerce 3.x

Owner

hannahswain commented Jul 21, 2017

Updated to work with WooCommerce 3.x

@mbtocalli

This comment has been minimized.

Show comment
Hide comment
@mbtocalli

mbtocalli Feb 19, 2018

How can I edit this field in the WP user-edit.php page?

mbtocalli commented Feb 19, 2018

How can I edit this field in the WP user-edit.php page?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment