• Resolved jimlongo

    (@jimlongo)


    I have a custom $_SESSION variable.
    I want to store it in the database upon order completion.

    Either as a new column in the posts table, or an additional row in the posts_meta table (any thoughts on which is better). Or I suppose it could be an additional table in the database.

    How do I insert that data from my session variable into the database?

    Thanks for any help, I’m pretty new to WooCommerce.

    http://wordpress.org/extend/plugins/woocommerce/

Viewing 13 replies - 31 through 43 (of 43 total)
  • Roy Ho

    (@splashingpixelscom)

    I don’t follow..why would it get wiped out and why would it update a second time?

    Thread Starter jimlongo

    (@jimlongo)

    by wiped out I’m referring to if the woocommerce plugin got updated, the file ‘class-wc-checkout.php’ would be overwritten and this mod would get lost. I need to figure out how to put it in a plugin or something so that it survives a plugin update.

    Roy Ho

    (@splashingpixelscom)

    oh…thought you’re talking about something else…

    Thread Starter jimlongo

    (@jimlongo)

    no problem, very nice work on your site btw.

    Now don’t lose interest . . . 🙂

    how can I move that hack to my plugin and call it during this checkout process?
    I tried this in my plugin which uses the same action as the code in class-wc-checkout
    but that doesn’t do it.

    add_action( 'woocommerce_checkout_update_user_meta', 'nfp_add_meta_webcode');
    
    function nfp_add_meta_webcode() {
    	$unique_code = 	$_SESSION['clientwebcode'];
    	update_post_meta( $order_id, '_webcode', $unique_code) ;
    }
    Roy Ho

    (@splashingpixelscom)

    First you have to find the right hook…And second your code is not correct. Your $order_id is undefined…

    You have to check the action hook’s argument list to see what is being passed on the callback and include that in your custom function.

    And why are you using that hook? I think you should use the first available checkout hook that processes the cart whether complete or not because you need to know if a purchase was made/attempted and what that was for…etc.

    Roy Ho

    (@splashingpixelscom)

    Here you go…I just found the perfect hook for you -> woocommerce_checkout_update_order_meta

    The first argument is the order id…you use that in your custom function

    Roy Ho

    (@splashingpixelscom)

    So do this:

    add_action( 'woocommerce_checkout_update_order_meta', 'nfp_add_meta_webcode', 10, 2 );
    
    function nfp_add_meta_webcode( $order_id, $order_posted ) {
    	$unique_code = 	$_SESSION['clientwebcode'];
    	update_post_meta( $order_id, '_webcode', $unique_code) ;
    }

    Roy Ho

    (@splashingpixelscom)

    Or this hook will work as well ‘woocommerce_checkout_order_processed’

    Thread Starter jimlongo

    (@jimlongo)

    Cool. I see those actions listed in the docs but no description of them. Where do you find the hook’s argument list?

    Roy Ho

    (@splashingpixelscom)

    I usually don’t look at docs…I look straight in the code…

    Thread Starter jimlongo

    (@jimlongo)

    That’s fantastic.
    Both those hooks seem to work, I don’t detect any difference yet.
    But that it’s working is a great relief.
    A Big Thank You.

    Roy Ho

    (@splashingpixelscom)

    No problem..hope it works out for you…

    Thread Starter jimlongo

    (@jimlongo)

    Thanks.

Viewing 13 replies - 31 through 43 (of 43 total)
  • The topic ‘custom order data into database’ is closed to new replies.