php - Woocommerce order->get_data() 抛出 PHP 致命错误:未捕获错误
问题描述
我有一个正在运行的函数,它首先检查帖子类型是否为“shop_order”,如果不是,则不应运行该函数。我正在使用return;
来结束它,但是当我尝试在“产品”帖子类型中添加新帖子时,我收到以下错误:
PHP Fatal error: Uncaught Error: Call to a member function get_data() on boolean in..
为什么说该功能get_data()
未捕获?post_type
如果不是,则此代码不应运行到这一点shop_order
。我什至打印出 $post_type 返回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();
}
}
解决方案
推荐阅读
- reactjs - 如何停止componentDidUpdate的无限循环?
- javascript - 从数组中获取值
- ios - Xcode - iOS 模拟器窗口为空白
- reactjs - Firebase 抛出错误 FirebaseApp 名称 [DEFAULT] 已存在
- mysql - MYSQL用另一个表中的名称替换id
- elasticsearch - logstash - 映射到带有转换的 json 数组
- here-api - 地理编码器停止返回形状
- search - 我正在使用支持 GPU 的 Milvus。但是为什么在我看来搜索有时比仅使用 CPU 的 Milvus 慢?
- python - Python OS - 使用“os.listdir”查看返回文件夹列表的目录。如何查看子文件夹的内容?
- scikit-learn - 无法在 colab 上运行 autosklearn