I am creating a WordPress and WooCommerce plugin which does the following:
- An anonymous user customizes a product on the page
- In a php script in the process, it creates an order in the database
- The user goes to the checkout page where the customer data, delivery etc. is requested.
By clicking on “Buy Now” WooCommerce creates a new order in the system and what I want is to update the order created earlier during the personalization process, adding customer details, payment, delivery etc. to the order.
is it possible?
Thanks!
You can use the function wc_update_order() to fetch an existing order object.
For a complete list of all the functions you can call on the order object, execute the following code after you fetch your order
This will list all the functions that are available to the Woocommerce Order object.
Hope this answers your question
Finally the solution is to update the values once the order has been made in the “thankyou.php” WooCommerce page.
Are updated as follows:
Previously, in a step of the process, I have kept in the session variable “_lm_product_data” information that interests me for the last step.
Hi Jorge I know it comes a little late, but i think this will suit your needs a little better than your solution. Actually this is the recomended way of doing this according to woocommerce. And it will work even if they dont reach the “thankyou” template for some reason. (for example, not finishing the payment proccess)
In my case i had to do this in order to add aditional information that I needed from my customers, for that specific purchase, so I decided to attach it to the order meta.
Basically you have to attach your custom function to a hook that gets executed on the creation of the order. This is an exaple using the hook that the plugin already provides so you can do your own things during the creation of the order:
Source: http://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
In this example they are adding an extra custom field added in the checkout page (not in the product purchase as you want), but this part of the code could be used to your situation by passing the information of your custom product(s) to the checkout form submmition (one option could be adding hidden inputs with style=”display:none” through javascript or on the php template that th eplugin offers).