问题
I'm developing a plugin with Woocommerce and Woosensei I can't seem to get the process working of creating an order programmatically, mark the order completed and activate the woosensei course for that particular person.
// create a new checkout instance and order id
$checkout = new WC_Checkout();
$this_order_id = $checkout->create_order();
// add some data to the order here //
[ ......... ]
// execute order
$order = new WC_Order($this_order_id);
$order->update_status('completed');
$learning = new WooThemes_Sensei();
$learning->sensei_woocommerce_complete_order($this_order_id);
$cart = new WC_Cart();
$cart->empty_cart();
The order is marked as complete indeed, but the user doesn't have access to the course. If I manually change the order back to in processing and after that to completed (in the WP admin), then the course is assigned to the user. This is really annoying, hope somebody has some cues (Woo is poorly documented ....) Thx in advance!
回答1:
Hmm, it seems like the sensei_woocommerce_complete_order function checks whether a user is logged in or not. So I duplicated that function and removed the 'logged in' check, and called that specific function when the user is not logged in. End to the grey hairs ... ;-)
来源:https://stackoverflow.com/questions/21126885/on-woocommerce-order-complete-activate-woosensei-course