I don’t follow..why would it get wiped out and why would it update a second time?
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.
oh…thought you’re talking about something else…
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) ;
}
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.
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
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) ;
}
Or this hook will work as well ‘woocommerce_checkout_order_processed’
Cool. I see those actions listed in the docs but no description of them. Where do you find the hook’s argument list?
I usually don’t look at docs…I look straight in the code…
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.
No problem..hope it works out for you…