Home › Forums › ACF PRO › Custom fields for registration woocommerce › Reply To: Custom fields for registration woocommerce
Well, with you advices, it seems to work.
If someone is interested :
/**
* Add custom fields to user / checkout
*/
add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );
function my_custom_checkout_field( $checkout ) {
echo '<div id="bv_custom_checkout_field"><h2>Measurements</h2>';
/* Weight */
woocommerce_form_field( 'weight_customer', array(
'type' => 'text',
'class' => array('my-class form-row-wide'),
'label' => __('Your weight'),
'placeholder' => __('Your weight'),
), get_user_meta( get_current_user_id(),'weight_customer' , true ) );
echo '</div>';
}
/**
* Verification
*/
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
function my_custom_checkout_field_process() {
// Check
if ( ! $_POST['weight_customer'] )
wc_add_notice( __( 'Do not forget weight.' ), 'error' );
}
* Update field
*/
add_action( 'woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta' );
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ( ! empty( $_POST['weight_customer'] ) ) {
update_user_meta( get_current_user_id(), 'weight_customer', sanitize_text_field( $_POST['weight_customer'], '' ));
}
}
I just don’t know how to tell him that it is a number (the weight) but it works.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.