Support » Plugins and Hacks » [Resolved] Add user meta upon checkout

[Resolved] Add user meta upon checkout

  • Hi,

    I am setting up a webshop using Woocommerce. It is a bespoke suit shop. Users can select fabrics etc. In the order process users can give their measurements. I am storing all size data in session array variable. The sizes output correctly in the cart (just tested using echo in cart.php) and also on checkout page (top of page class-wc-checkout.php).

    But when I want to add the sizes to the user meta, using add_user_meta , the meta_key is stored in the database, but the meta_value is empty.

    I use this code around line 252 in class-wc-checkout.php:

    if ( $this->customer_id )
    do_action( ‘woocommerce_checkout_update_user_meta’, $this->customer_id, $this->posted );

    add_user_meta( $this->customer_id, ‘_size1’, $size1);

    Is my session data somehow destroyed when the “place order” button is clicked?

    In the above example I only store the first item of the array in the database. I would like to store the array itself.

    Can anyone please help me with getting my sizes array in the wp_usermeta table?

    Thanks in advance!!


Viewing 3 replies - 1 through 3 (of 3 total)
  • Update:

    The sizes must be stored to the database only if a new user is created. So the code goes somewhere around line 650, in the if:

    // if there are no errors, let’s create the user account
    if ( ! $reg_errors->get_error_code() ) {

    after line:
    do_action( ‘woocommerce_created_customer’, $this->customer_id );
    add_user_meta( $this->customer_id, ‘_size1’, $size1);

    Anyone??? Please I’m desperate 🙂

    Ok, maybe I have to rephrase my question with an example.

    On the products page I have a text input field. User has to enter a number in the field. I save this value in $_SESSION(‘number’)

    Now.. How can I save this $_SESSION(‘number’) in the wp database if a new user is created on checkout. I want to save this $_SESSION(‘number’) in the wp_usermeta table, together with all the other user info.


    Ah.. my open question…

    I solved this by adding the meta data to teh db in the order-details.php. This is shown after a user completes his order. Here my session variables are accessible. I still don’t know why my session vars aren’t accessible when a new user is created.

    Anyway this workaround works.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Add user meta upon checkout’ is closed to new replies.