2016-11-18 134 views
-1

我正在尝试编写Wordpress Woocommerce,因此所有新订单都通过订单状态标记为“完成”。代码不起作用。我究竟做错了什么?Woocommerce默认订单状态

我已将此添加的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'); 
    } 
} 
+0

删除功能'autocomplete_orders'和留在它的代码在'functions.php' –

+0

您需要添加一个动作叫' autocomplete_orders()',显然情况并非如此。 woocommerce_thankyou的行动永远不会失火没有它 – Benoti

+0

http://stackoverflow.com/questions/35686707/woocommerce-auto-complete-paid-orders-depending-on-payment-methods/35689563#35689563 – LoicTheAztec

回答

2
add_action('woocommerce_thankyou', 'autocomplete_all_orders'); 
function autocomplete_all_orders($order_id) { 

    if (! $order_id) { 
     return; 
    } 

    $order = wc_get_order($order_id); 
    $order->update_status('completed'); 
}