当前位置: 首页 > 知识库问答 >
问题:

第80行的woocommerce/includes/wc-notice-functions.php上null的成员函数get()

宰父霖
2023-03-14

我在一个WooCommerce运输插件,我有一个类方法与以下是触发自定义do_action

try {
    $client = new SoapClient( plugin_dir_path( dirname( __FILE__ ) ) . 'includes/wsdl/Test.wsdl', ['trace' => true, 'exceptions' => true ]  );
    $results = $client->__soapCall('CreateSomml', ['parameters' =>  ['Details' => $bill->__toArray() ]]);
} catch (SoapFault $e) {
    wc_add_wp_error_notices(new WP_Error('soap', $e->getMessage(), isset($client)? $client->__getLastRequest() : $bill->__toArray() ));
    // print $client->__getLastRequest();
    // throw $e;
}

它尝试连接到web服务,并将捕获任何SoapFault并添加错误通知,但在运行代码时,我遇到了错误

致命错误:在第80行的../wp content/plugins/woocommerce/includes/wc-notice-functions.php中调用null上的成员函数get()

根据文件,这将导致

function wc_add_notice( $message, $notice_type = 'success' ) {
    if ( ! did_action( 'woocommerce_init' ) ) {
        wc_doing_it_wrong( __FUNCTION__, __( 'This function should not be called before woocommerce_init.', 'woocommerce' ), '2.3' );
        return;
    }

    $notices = WC()->session->get( 'wc_notices', array() );

    // Backward compatibility
    if ( 'success' === $notice_type ) {
        $message = apply_filters( 'woocommerce_add_message', $message );
    }

    $notices[ $notice_type ][] = apply_filters( 'woocommerce_add_' . $notice_type, $message );

    WC()->session->set( 'wc_notices', $notices );
}

第80行是return

我想可能是的

WC()-

正在从后端管理触发该操作。有什么问题吗?

我使用Wordpress 4.8和Woocommerce 3.2.1运行PHP5.6.27

更新:

我一直在努力找出错误,我能想到的就是

致命错误:未捕获错误:在/var/www/wordpress/wp content/plugins/woocmerce/includes/wc通知函数中调用null上的成员函数get()。php:80堆栈跟踪:#0/var/www/wordpress/wp content/plugins/woocmerce/includes/wc通知函数。php(198):wc_添加通知('Invalid User Cr.,'error'))#1/var/www/wordpress/wp content/plugins/wc trinicargo shipping/includes/class wc trinicargo shipping create waybill.php(80):wc_add_wp_error_notices(Object(wp_error))#2/var/www/wordpress/wp includes/class wp hook.php(296):wc_trinicargo_shipping_create_waybill-

为什么会议没有开始?我怎么开始呢?


共有1个答案

乔宏峻
2023-03-14

因此,对于任何想要解决这个问题的人来说,问题在于WC()-

WC()->session = new WC_Session_Handler();
WC()->session->init();

在这两行之后,我成功地使用了wc_add_notice。希望这能帮助别人。

 类似资料:
  • 我收到WordPress发来的关于致命错误的消息。它与WPML字符串翻译插件后端中的特定页面相关。我认为有一个特别的翻译: 访问发现错误的页面(xxxxxxxx/wp admin/admin.php?page=wpml translation management/menu/translations-queue.php) 它还说 错误详细信息===========在文件/nas/content/l

  • 我试图在我的商店里编辑wc-template-functions.php,但做错了什么。 现在我在281线上得到致命错误。 致命错误:未捕获错误:在 /home/kidsandm/oliverthedog/wp-content/plugins/woocommerce/includes/wc-template-functions.php:282堆栈跟踪中找不到类常量:#0 /home/kidsand

  • 我试图为我在Github上的一个项目创建一个新的虚拟开发环境。我已经安装了MariaDB,PHP 7,做了一个本地克隆的存储库,并恢复了它的. env文件。它应该起作用了。 不幸的是,当我键入php artisan和作曲家更新,我收到以下错误: PHP致命错误:未捕获错误:调用成员函数连接()在src/供应商/laravel/框架/src/照明/数据库/雄辩/Model.php:1058 堆栈跟踪

  • 我正在尝试使用PHP在WooCommerce中创建一个自定义优惠券代码,它基本上会将购物车中标签名为“main”的每件商品的价格折扣到10。它通过计算购物车中标记为“main”的商品数量,然后计算每个商品的总价,并由此计算$折扣变量中所需的折扣。请参见下面的代码: 当我尝试激活此代码时,会收到以下错误消息: 您试图保存的代码段在第4行产生了致命错误: 未捕获错误:在/homepages/9/d39

  • 我有5个类别Categoria、Produto、Subcategoria、submoduto和Comanda,对于所有类别中的执行搜索,我尝试提供如下服务: 我尝试访问ComandaController上的服务 然后symfony返回错误 我services.yml有 怎么了?

  • 我面临着这个问题。 致命错误:未捕获错误:对成员函数的调用为null上的_type() 有人能在这方面帮助我吗。 这是我使用的代码。 任何帮助都将不胜感激。谢谢