第80行的wooccommerce/includs/wc-notice-functions.php上的成员函数get()



我正在开发一个Wooccommerce运输插件,其中我有一个类方法,该方法在自定义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并添加错误通知,但在运行代码时,我遇到了错误

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

基于文档导致

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()->session->set( 'wc_notices', $notices );但不确定错误的原因。

该操作是由后端管理员管理触发的。问题出在哪里?

我使用Wordpress 4.8和Wooccommerce 3.2.1 运行PHP 5.6.27

更新:

一直在努力寻找错误,我能想到的只有

致命错误:未捕获错误:在/var/www/wordpress/wp-content/plugins/woocomerce/included/wc notice functions.php:80堆栈跟踪:#0/var/www/wordpress/wp-content/plugins/woocomerce/included-wc notice函数.php(198):wc_add_notification('Invalid User Cr..','error')#1/var/www/wordpress/wp-content/plugins/wc-trinicargo-shipping/includes/class-wc-trinicargo-shipping-create-wpboard.php(80):wc_add_wp_error_notifications(对象(wp_error))#2/var/ww/wordpress/wp-includes/class-wp-hook.php(296):wc_trinicargo_shipping_create_waybill->create()#3/var/ww/wwordpress/wp-includes-class-wp-hook.php(323):wp_hook->apply_filters('',Array)#4/var/www/wordpress/wp includes/plugin.php/第80行上的var/www/wordpress/wp-content/plugins/woocommerce/includes/wc-notice-functions.php

为什么会话没有启动?我该如何开始?

因此,对于任何正在寻找解决方案的人来说,问题是这里还没有WC()->会话。我在尝试在"admin_post"操作中添加通知时遇到了这个问题。在这里初始化一个空会话对我有效:

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

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

最新更新