对非对象调用成员函数get_order()。。。调用function.php中的wc_create_order()创建新订单时

对非对象调用成员函数get_order()。。。调用function.php中的wc_create_order()创建新订单时,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,当我使用woocommerce插件在function.php中创建主题的新顺序时 $order = wc_create_order(); 它向我显示了一个错误 Fatal error: Call to a member function get_order() on a non-object in ../wc-order-functions.php on line 58 &当我打开它包含的文件时 return WC()->order_factory->get_order( $th

当我使用woocommerce插件在function.php中创建主题的新顺序时

$order = wc_create_order();
它向我显示了一个错误

Fatal error: Call to a member function get_order() on a non-object in ../wc-order-functions.php on line 58
&当我打开它包含的文件时

return WC()->order_factory->get_order( $the_order );
我得到的文件是

    $order = wc_create_order();
    $order->add_product( get_product( '2319' ), 2 );
    $order->set_address( $address, 'billing' );
    $order->set_address( $address, 'shipping' );
    $order->calculate_totals();
在github上提供,但不起作用

请在这方面帮助我。提前谢谢

 $order = wc_create_order();
 $custaddress=array(
       // array fields here
    );
        $order->add_product( get_product( '12' ), 2 ); //(get_product with id and next is for quantity)
        $order->set_address( $custaddress, 'billing' );
        $order->set_address( $custaddress, 'shipping' );
        $order->add_coupon('Fresher','10','2'); // accepted param $couponcode, $couponamount,$coupon_tax
        $order->calculate_totals();
用你的函数调用上面的代码,它就会相应地工作


注意:代码不适用于早期版本2.2。

这就像
返回wc\u get\u订单($order\u id)适用于可能重复的退货WC()->订单工厂->获取订单($U订单);是在woocommerce的核心文件中定义的,我无法更改。我使用wc_create_order();&它在admin中生成orderid,但显示了致命错误。我正在使用WordPress 4.4.2&仍然是抛出致命错误我说的是woocommerce插件,不是WordPress它的woocommerce 2.5.2这是我获得代码的链接。。。。