douzhanhui5662 2019-01-24 10:40
浏览 85

Woocommerce order-> get_data()抛出PHP致命错误:未捕获错误

I have a function running which first checks to the see if the post type is 'shop_order' and if it's not then the function shouldn't be run. I'm using the return; to end it but when I try adding a new post in the 'product' post type i get the following error:

 PHP Fatal error:  Uncaught Error: Call to a member function get_data() on boolean in.. 

Why is it saying the function get_data() is uncaught? This code shouldn't run to this point if the post_type is not shop_order. I've even printed out $post_type which returns product.

function woocommerce_process_shop_order ( $post_id, $post, $update ) {

    if (isset($post->post_status) && 'auto-draft' == $post->post_status) {
      return;
    }
        // Autosave, do nothing
        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
        return;
    }
        // AJAX? Not used here
        if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
        return;
    }
        // Check user permissions
        if ( ! current_user_can( 'edit_post', $post_id ) ) {
          return;
    }

    // don't run the echo if the function is called for saving revision.
    if ( $post->post_type == 'revision' ) {
       return;
    }

        $post_type = get_post_type($post_id);
    error_log( print_r( $post_type, true ) );

   // terminate early if post type is not 'post' and if we are updating post object and not creating it.
   if ( "shop_order" != $post_type && !$update ) {
       return;
       error_log( print_r( 'not shop order', true ) );
   }

  $is_new = $post->post_date === $post->post_modified;

  if ( $is_new ) {

    $order = wc_get_order( $post_id );
    $order_data = $order->get_data();

  }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 乘性高斯噪声在深度学习网络中的应用
    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥30 python代码,帮调试,帮帮忙吧