Open rayjamesdev opened 1 year ago
Well, hook_uc_checkout_complete()
takes action when checkout is complete, but it's only one part of a whole sequence of actions that happen upon completion. So the order isn't necessarily fully complete at the time it's called.
And it's called within the function uc_cart_complete_sale()
, where you'll find (lines 894–5),
// Invoke the checkout complete trigger and hook.
$account = user_load($order->uid);
module_invoke_all('uc_checkout_complete', $order, $account);
rules_invoke_event('uc_checkout_complete', $order);
Note that the hook is called BEFORE the Rules event is called. This is significant, because the granting of the role to the user is effected by a rule (specifically, by uc_roles_action_order_renew()
, which is a Rules action).
So the order isn't completely complete at the time that hook_uc_checkout_complete()
is called.
Once the order is completely complete, you can find the granted role in the account's roles—after the rule has been invoked.
If you need to programmatically get to that point, you could set up your own rule to run on the uc_checkout_complete
event, and set the order so it fires after uc_roles
's rule. (I think.)
Ok, thanks for the explanation. I'll try to set that up and report back. Thanks.
@rayjamesdev, did you achieve success with the suggested approach?
Hi, in hook_uc_checkout_complete($order, $account), when I look at the output of $order, it shows [order_status] => pending, and not completed. Also, when I look at the output of $account, it doesn't show the role that was included with part of the purchase(uc_roles). How do I get to the data after the order is officially completed and the payment has gone through?
reference: hook_uc_checkout_complete($order, $account) on line 261 of uc_cart.api.php
Modules Used:
Thanks.