user account number field cannot be extracted
-
Hi i inserted user account field but when i want to extract for certain customer the data the account number field appears empty.
-
“account number” is non-standard field.
Please, reply to my previous questionokay so is there a way to create a field
this screen shot will show that i have a ship to/ account number in wordpress. i added this using a code. and it is appearing in export field too now when i download it it does not show the data inserted in it.
This is my question
Please, paste this code here.
I must setup same field on my website to reproduce the problem.
// Display a field in Registration / Edit account
add_action( ‘woocommerce_register_form_start’, ‘display_account_registration_field’ );
add_action( ‘woocommerce_edit_account_form_start’, ‘display_account_registration_field’ );
add_action( ‘woocommerce_checkout_details_form’, ‘display_account_registration_field’ );
function display_account_registration_field() {
$user = wp_get_current_user();
$value = isset($_POST[‘billing_account_number’]) ? esc_attr($_POST[‘billing_account_number’]) : $user->billing_account_number;
?>
<p class=”woocommerce-form-row woocommerce-form-row–wide form-row form-row-wide”>
<label for=”reg_billing_account_number”><?php _e( ‘Ship to/ Account number’, ‘woocommerce’ ); ?> <span class=”required”>*</span></label>
<input type=”text” maxlength=”6″ class=”input-text” name=”billing_account_number” id=”reg_billing_account_number” value=”<?php echo $value ?>” />
</p>
<div class=”clear”></div>
<?php
}// registration Field validation
add_filter( ‘woocommerce_registration_errors’, ‘account_registration_field_validation’, 10, 3 );
function account_registration_field_validation( $errors, $username, $email ) {
if ( isset( $_POST[‘billing_account_number’] ) && empty( $_POST[‘billing_account_number’] ) ) {
$errors->add( ‘billing_account_number_error’, __( ‘Error: account number is required!’, ‘woocommerce’ ) );
}
return $errors;
}
// login Field validation
add_filter( ‘woocommerce_login_errors’, ‘account_login_field_validation’, 10, 3 );
function account_login_field_validation( $errors, $username, $email ) {
if ( isset( $_POST[‘billing_account_number’] ) && empty( $_POST[‘billing_account_number’] ) ) {
$errors->add( ‘billing_account_number_error’, __( ‘Error: account number is required!’, ‘woocommerce’ ) );
}
return $errors;
}// Save registration Field value
add_action( ‘woocommerce_created_customer’, ‘save_account_registration_field’ );
function save_account_registration_field( $customer_id ) {
if ( isset( $_POST[‘billing_account_number’] ) ) {
update_user_meta( $customer_id, ‘billing_account_number’, sanitize_text_field( $_POST[‘billing_account_number’] ) );
}
}// Save Field value in Edit account
add_action( ‘woocommerce_save_account_details’, ‘save_my_account_billing_account_number’, 10, 1 );
function save_my_account_billing_account_number( $user_id ) {
if( isset( $_POST[‘billing_account_number’] ) )
update_user_meta( $user_id, ‘billing_account_number’, sanitize_text_field( $_POST[‘billing_account_number’] ) );
}// Save Field value in Checkout
add_action( ‘woocommerce_save_checkout_details’, ‘save_checkout_billing_account_number’, 10, 1 );
function save_checkout_billing_account_number( $user_id ) {
if( isset( $_POST[‘billing_account_number’] ) )
update_user_meta( $user_id, ‘billing_account_number’, sanitize_text_field( $_POST[‘billing_account_number’] ) );
}// Display field in admin user billing fields section
add_filter( ‘woocommerce_customer_meta_fields’, ‘admin_user_custom_billing_field’, 10, 1 );
function admin_user_custom_billing_field( $args ) {
$args[‘billing’][‘fields’][‘billing_account_number’] = array(
‘label’ => __( ‘Ship to/ Account number’, ‘woocommerce’ ),
‘description’ => ”,
‘custom_attributes’ => array(‘maxlength’ => 6),
);
return $args;
}Hello
So you added key “USER__billing_account_number” to export , but you see empty cell?
thanks, Alex
No the ship to/account number is added defaulted because of the user backend detail but when i export the column is empty
https://paste.pics/5I799Hi
Wordpress damaged your code.
Can you upload it as attachment to helpdesk?sure i will do that is it possible that my problem get solved by today
I’ve replied, I need your custom code.
But you call “update_user_meta”, so you should see this field in dropdown.
See this screenshot https://imgur.com/QC9DI0x
- The topic ‘user account number field cannot be extracted’ is closed to new replies.