L
L
legatobrown2020-11-16 11:00:47
WordPress
legatobrown, 2020-11-16 11:00:47

How to make in woocommerce that the data from the input in the personal account gets to the delivery address and the company?

I added input fields on the personal account page, where you enter your login phone and mail. Added fields Address and Company.
How to make the data entered in these fields get into woocommerce in the shipping address and company sections?

so I added fields for woocommerce_edit_account_form in the function.php file, what do I need to fix - add in the code so that the data from these fields gets to the delivery address and delivery company for an authorized user in the wordpress admin panel?

add_action( 'woocommerce_edit_account_form', 'add_favorite_adress_to_edit_account_form' );
function add_favorite_adress_to_edit_account_form() {
    $user = wp_get_current_user();
    ?>
    <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide row-adress">
        <label for="favorite_adress"><?php _e( 'Адрес', 'woocommerce' ); ?></label>
        <input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="favorite_adress" id="favorite_adress" value="<?php echo esc_attr( $user->favorite_adress ); ?>" />
    </p>
    <?php
}

// Save the custom field 'favorite_color'
add_action( 'woocommerce_save_account_details', 'save_favorite_adress_account_details', 12, 1 );
function save_favorite_adress_account_details( $user_id ) {
    // For Favorite color
    if( isset( $_POST['favorite_adress'] ) )
        update_user_meta( $user_id, 'favorite_adress', sanitize_text_field( $_POST['favorite_adress'] ) );

    // For Billing email (added related to your comment)
    if( isset( $_POST['account_email'] ) )
        update_user_meta( $user_id, 'billing_email', sanitize_text_field( $_POST['account_email'] ) );
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question