在非对象上调用成员函数get_order()...同时在function.php中调用wc_create_order()来创建新的顺序

时间:2016-04-06 11:05:47

标签: 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( $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上给出但没有工作。

请帮助我。谢谢。

1 个答案:

答案 0 :(得分:0)

{{1}}

使用您的函数调用上面的代码然后它将相应地工作。

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