On Woocommerce order complete, activate woosensei course

自古美人都是妖i 提交于 2019-12-23 03:44:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!