【问题标题】:Call to a member function get_items() on a non object in woocommerce在 woocommerce 中调用非对象上的成员函数 get_items()
【发布时间】:2018-10-17 06:16:44
【问题描述】:

我正在制作一个与 woocommerce WordPress 插件协作的插件。尝试获取订单商品时出现错误:

“致命错误:在第 283 行的 /home/telesqua/public_html/mehtab/wp-content/plugins/order-grabber/order-grabber.php 中的非对象上调用成员函数 get_items()”

这就是第 283 行及其周围的内容:

function post_order() 
{
if(isset($order_id))
{   
$order = new WC_Order($order_id);
}
$items = $order->get_items();
$number_of_items_in_this_order = $order->get_item_count();

谁能帮我指出问题?如果需要,我可以提供源文件。

【问题讨论】:

  • 可能 $order_id 没有设置,所以对象 $order 没有创建(WC_Order() 类没有实例化)。
  • 非常感谢 jan Relilink 的回复。你是完全正确的,我对此有完全相同的想法,我想问的是,这个类没有被实例化是有原因的。

标签: wordpress woocommerce


【解决方案1】:

这是因为使用上述代码后必须执行add_action

add_action('init', 'post_order');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-01
    • 2010-09-26
    • 2012-04-20
    • 2015-05-01
    • 2014-08-07
    • 2013-12-01
    • 2015-12-23
    • 2015-08-29
    相关资源
    最近更新 更多