Title: custom order data into database
Last modified: August 20, 2016

---

# custom order data into database

 *  Resolved [jimlongo](https://wordpress.org/support/users/jimlongo/)
 * (@jimlongo)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/custom-order-data-into-database/)
 * 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/](http://wordpress.org/extend/plugins/woocommerce/)

Viewing 15 replies - 1 through 15 (of 43 total)

1 [2](https://wordpress.org/support/topic/custom-order-data-into-database/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/custom-order-data-into-database/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/custom-order-data-into-database/page/2/?output_format=md)

 *  [Roy Ho](https://wordpress.org/support/users/splashingpixelscom/)
 * (@splashingpixelscom)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/custom-order-data-into-database/#post-3474825)
 * I can tell you the best approach however I would first need to know what you’re
   doing and why you’re doing it. What is in the data…etc. Once I know that, I can
   better give you my suggestion.
 *  Thread Starter [jimlongo](https://wordpress.org/support/users/jimlongo/)
 * (@jimlongo)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/custom-order-data-into-database/#post-3474828)
 * Thanks,
 * Each product is unique to that client.
 * Let’s say it’s a photo of them. They are given a Number at the time it’s taken
   which they enter into a form on the website.
 * I capture the number into a variable from a form, and they can now see it on 
   the website and buy it. (the number is parsed and let’s us get the photo from
   a CDN to display on the website)
 * After they buy it I need to identify which photo they purchased. Hence the need
   to capture the session variable into the database for further use in the order
   emails and admin order details, etc.,
 *  [Roy Ho](https://wordpress.org/support/users/splashingpixelscom/)
 * (@splashingpixelscom)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/custom-order-data-into-database/#post-3474836)
 * hmmmm…bare with me as I try to understand this…each order is already unique to
   a customer so why do you need an extra number?
 *  Thread Starter [jimlongo](https://wordpress.org/support/users/jimlongo/)
 * (@jimlongo)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/custom-order-data-into-database/#post-3474840)
 * To identify which photo belongs to their order. The only identifier is the session
   variable I’ve captured. Otherwise it could be any of 1000’s of photos they just
   purchased.
 *  [Roy Ho](https://wordpress.org/support/users/splashingpixelscom/)
 * (@splashingpixelscom)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/custom-order-data-into-database/#post-3474842)
 * Ok well I still don’t understand what you need that for because why would they
   buy 1000 photos that is not their own?
 * But anyways, to answer your question in general, use the transient API instead
   of sessions.
 *  Thread Starter [jimlongo](https://wordpress.org/support/users/jimlongo/)
 * (@jimlongo)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/custom-order-data-into-database/#post-3474844)
 * Of course they wouldn’t. But I need to be able to identify which picture they
   purchased. Right now all I know is that Joe Brown, address, etc., bought a photo.
   Which one did he buy?
 *  [Roy Ho](https://wordpress.org/support/users/splashingpixelscom/)
 * (@splashingpixelscom)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/custom-order-data-into-database/#post-3474845)
 * I thought the photo IS the product….
 *  Thread Starter [jimlongo](https://wordpress.org/support/users/jimlongo/)
 * (@jimlongo)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/custom-order-data-into-database/#post-3474847)
 * Yes but there is only 1 product for sale right now. A printed photo (otherwise
   there would be 10 of 1000’s of products and growing by the minute).
 * What is unique is that your photo is different from mine.
 * So if you buy the product, I need to know the variable that identifies it as 
   your photo.
 * BTW, thanks for your patience in trying to help.
 *  [Roy Ho](https://wordpress.org/support/users/splashingpixelscom/)
 * (@splashingpixelscom)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/custom-order-data-into-database/#post-3474848)
 * I know what you’re saying but to me 1 photo is 1 product. So it is already unique.
   so even if you have 10,000 photos, that is 10,000 unique products…
 * And you can purge them after a certain time, so your product base will not get
   too big…
 * Or am I missing something? Perhaps you didn’t fully explain how these photos 
   come about and how they are entered into the system.
 *  Thread Starter [jimlongo](https://wordpress.org/support/users/jimlongo/)
 * (@jimlongo)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/custom-order-data-into-database/#post-3474852)
 * The products aren’t ever entered into my system. There’s no process for that.
 * I use the identifier to grab the image from the CDN to display on the product
   page. But there is only 1 product page.
 *  [Roy Ho](https://wordpress.org/support/users/splashingpixelscom/)
 * (@splashingpixelscom)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/custom-order-data-into-database/#post-3474858)
 * Ok…Then the easier way is to use that identifier and save that along with the
   order as a post meta. Because an order in WooCommerce is a custom post type as“
   shop_order”. This way the order will always be tied to that unique identifier
   and you won’t need to deal with sessions.
 *  Thread Starter [jimlongo](https://wordpress.org/support/users/jimlongo/)
 * (@jimlongo)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/custom-order-data-into-database/#post-3474867)
 * Yes that’s what I was thinking – add it to wp_post meta.
    My question is how 
   to go about that. I’m not that familiar with WP, do I need to create an action?
   And I can’t see any examples of how to insert data into the database.
 * i was looking at the woocommerce_order_status_completed hook, I’m not sure how
   best to proceed.
 *  [Roy Ho](https://wordpress.org/support/users/splashingpixelscom/)
 * (@splashingpixelscom)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/custom-order-data-into-database/#post-3474873)
 * In the hook just find the unique post id from the order and from there you can
   use the update_post_meta function.
 * So something like:
 * update_post_meta( $order_id, ‘_unique_identifier’, $photo_id );
 *  Thread Starter [jimlongo](https://wordpress.org/support/users/jimlongo/)
 * (@jimlongo)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/custom-order-data-into-database/#post-3474875)
 * Are you talking about the function [http://codex.wordpress.org/Function_Reference/add_post_meta](http://codex.wordpress.org/Function_Reference/add_post_meta)
 * Not sure where it goes or how to use it, but it looks promising
 *  [Roy Ho](https://wordpress.org/support/users/splashingpixelscom/)
 * (@splashingpixelscom)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/custom-order-data-into-database/#post-3474879)
 * Use update_post_meta instead…You use it in the hook of the completed order.

Viewing 15 replies - 1 through 15 (of 43 total)

1 [2](https://wordpress.org/support/topic/custom-order-data-into-database/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/custom-order-data-into-database/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/custom-order-data-into-database/page/2/?output_format=md)

The topic ‘custom order data into database’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)

 * 43 replies
 * 2 participants
 * Last reply from: [jimlongo](https://wordpress.org/support/users/jimlongo/)
 * Last activity: [13 years, 4 months ago](https://wordpress.org/support/topic/custom-order-data-into-database/page/3/#post-3474952)
 * Status: resolved