I am creating a Wordpress and WooCommerce plugin which does the following:
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:
/**
* Update the order meta with field value
*/
add_action( 'woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta' );
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ( ! empty( $_POST['my_field_name'] ) ) {
update_post_meta( $order_id, 'My Field', sanitize_text_field( $_POST['my_field_name'] ) );
}
}
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).