Ken*_*AUD 1 php wordpress woocommerce
我正在开发一个 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;
}
Run Code Online (Sandbox Code Playgroud)
它尝试连接到 Web 服务并会捕获任何SoapFault并添加错误通知但在运行代码时我遇到了错误
致命错误:调用成员函数 get() on null in ...../wp-content/plugins/woocommerce/includes/wc-notice-functions.php on line 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 );
}
Run Code Online (Sandbox Code Playgroud)
我想这可能是
WC()->session->set( 'wc_notices', $notices ); 但不确定为什么会出错。
该操作是从后端管理员管理触发的。这可能是问题所在?
我正在使用 Wordpress 4.8 和 Woocommerce 3.2.1 运行 PHP 5.6.27
更新:
一直试图找到错误,我能想到的是
致命错误:未捕获错误:调用成员函数 get() on null in /var/www/wordpress/wp-content/plugins/woocommerce/includes/wc-notice-functions.php:80 堆栈跟踪:#0 /var /www/wordpress/wp-content/plugins/woocommerce/includes/wc-notice-functions.php(198): wc_add_notice('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->create() #3 /var/www/wordpress/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters('',数组)#4 /var/www/wordpress/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #5 /var/www/wordpress/wp-content/plugins/wc-trinicargo-shipping/includes/class-wc-trinicargo-shipping-create-waybill.php(68): do_action('wc_trinicargo_c.. .') #6 /var/www/wordpress/wp-content/plugins/wc-trinicargo-shipping/admin/partials/wc-trinicargo-shipping-init-methods.php(163): Wc_ in /var/www/ wordpress/wp-content/plugins/woocommerce/includes/wc-notice-functions.php 第 80 行
为什么会话没有开始?我该如何开始?
因此,对于任何正在寻找解决方案的人来说 - 问题是 WC()->session 在这里尚不可用。我在尝试在“admin_post”操作中添加通知时遇到了这个问题。在这里初始化一个空会话对我有用:
WC()->session = new WC_Session_Handler();
WC()->session->init();
Run Code Online (Sandbox Code Playgroud)
在这两行之后,我能够成功使用 wc_add_notice。希望能帮助某人。
| 归档时间: |
|
| 查看次数: |
2650 次 |
| 最近记录: |