• 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 15 replies - 1 through 15 (of 43 total)
  • Roy Ho

    (@splashingpixelscom)

    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

    (@jimlongo)

    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

    (@splashingpixelscom)

    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

    (@jimlongo)

    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

    (@splashingpixelscom)

    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

    (@jimlongo)

    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

    (@splashingpixelscom)

    I thought the photo IS the product….

    Thread Starter jimlongo

    (@jimlongo)

    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

    (@splashingpixelscom)

    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

    (@jimlongo)

    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

    (@splashingpixelscom)

    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

    (@jimlongo)

    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

    (@splashingpixelscom)

    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

    (@jimlongo)

    Are you talking about the function 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

    (@splashingpixelscom)

    Use update_post_meta instead…You use it in the hook of the completed order.

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