I’m developing a simple WordPress plugin that adds some credits to a table when the admin marks a order as “completed”.
My plugin.php looks like this:
<?php
function add_credits($order_status, $order_id) {
global $wpdb, $woocommerce, $current_user;
$order = new WC_Order($order_id);
$items = $order->get_items();
//DO SOME STUFF HERE with items and order
}//function
add_action('woocommerce_order_status_completed', 'add_credits');
But, when I change the order to “COMPLETE”, this plugin does not make nothing. I can even write an echo or a simple instruction at the first line of the function, and doesn’t run.
The function
add_credits
should take only one parameter:function add_credits($order_id) {
Also make sure your plugin is activated in WordPress.
You can check the sourcecode containing the specific
do_action
call here:http://docs.woothemes.com/wc-apidocs/source-class-WC_Order.html#_update_status