0

I am trying to code Wordpress Woocommerce so all new orders are marked as "complete" by order status. The code is not working. What am I doing wrong?

I added this to functions.php:

function autocomplete_orders() {
    add_action('woocommerce_thankyou', 'autocomplete_all_orders');
    /**
     * sp_autocomplete_all_orders 
     *
     * Register custom tabs Post Type
     *
     * @param   int $order_id
     *
     * @return  null
     */
    function autocomplete_all_orders($order_id) {
        global $woocommerce;

        if (!$order_id)
            return;
        $order = new WC_Order($order_id);
        $order->update_status('completed');
    }
}
Stanimir Stoyanov
  • 1,876
  • 1
  • 15
  • 20
Udi Skiri
  • 11
  • 1
  • Remove the function `autocomplete_orders` and leave the code in it in your `functions.php` – Stanimir Stoyanov Nov 18 '16 at 08:45
  • You need to add an action to call `autocomplete_orders()` , apparently this is not the case. woocommerce_thankyou action will never fire without it – Benoti Nov 18 '16 at 08:45
  • http://stackoverflow.com/questions/35686707/woocommerce-auto-complete-paid-orders-depending-on-payment-methods/35689563#35689563 – LoicTheAztec Nov 18 '16 at 18:37

1 Answers1

5
function autocomplete_all_orders( $order_id ) { 
    if ( ! $order_id ) return;
    
    $order = wc_get_order( $order_id );
    $order->update_status( 'completed' );
}
add_action( 'woocommerce_thankyou', 'autocomplete_all_orders' );
kanlukasz
  • 1,103
  • 19
  • 34
Jay Gosai
  • 279
  • 1
  • 11