簡體   English   中英

成員函數get()在woocommerce / includes / wc-notice-functions.php上的第80行上為null

[英]member function get() on null on woocommerce/includes/wc-notice-functions.php on line 80

我正在使用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()->session->set( 'wc_notices', $notices ); 但不確定為什么會出錯。

該操作是由后端管理員管理觸發的。 帽子可能是問題嗎?

我正在使用Wordpress 4.8和Woocommerce 3.2.1運行PHP 5.6.27

更新:

一直試圖找到錯誤,我所能想到的是

致命錯誤:未被捕獲的錯誤:在/var/www/wordpress/wp-content/plugins/woocommerce/includes/wc-notice-functions.php:80中調用成員函數get()時為null堆棧跟蹤:#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 / include / class-wc-trinicargo-shipping-create-waybill.php(68):do_action('wc_trinicargo_c ...')#6 / var / www / wordpress / wp-content / plugins / wc-trinicargo-shipping / admin /分音/ WC-trinicarg o-shipping-init-methods.php(163):第80行上的/var/www/wordpress/wp-content/plugins/woocommerce/includes/wc-notice-functions.php中的Wc_

為什么會話沒有開始? 我該如何開始呢?

因此,對於任何尋求對此解決方案的人來說,問題在於WC()-> session在此尚不可用。 我遇到了嘗試在“ admin_post”操作中添加通知的問題。 在這里初始化一個空會話對我有用:

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

在這兩行之后,我能夠成功使用wc_add_notice。 希望能幫助到別人。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM