亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

WooCommerce 自定義插件:WC_Customer 對象實例周圍的錯誤

WooCommerce 自定義插件:WC_Customer 對象實例周圍的錯誤

PHP
嗶嗶one 2023-04-21 15:51:06
我構建了一個插件,但遇到以下問題:WooCommerce 儀表板(在管理端)不會加載數據。它掛起并失敗。我已經跟蹤了問題代碼:中的問題if ( is_admin() ) {     //removed   } else if ( !$this->is_login_page() && !wp_doing_ajax() ) {    $public = new Public();}這是導致問題的公共端代碼!is_admin 或 wp_doing_ajax 都不能阻止它發生。在公共方面,我打電話add_action( 'init', array('Dynamic_Rules', 'dynamic_rule_tax_exemption') );在免稅功能中,我特別有這段代碼導致了問題:$woocommerce = WC();$user_country = $woocommerce->customer->get_billing_country();$woocommerce->customer->set_is_vat_exempt(true);所以我只能推測發生了什么,也許 WC() 以某種方式將所有內容發送到無限循環中,這就是儀表板不加載數據的原因。我不知道為什么 is_admin() 和 wp_doing_ajax() 不能阻止這種情況發生。也許我在 init 上調用該函數是錯誤的,但我還能在哪里調用它呢?
查看完整描述

1 回答

?
慕運維8079593

TA貢獻1876條經驗 獲得超5個贊

很難找出您的問題可能是什么……請注意“您的問題應該更新為包括所需的行為、特定問題或錯誤,以及重現問題所需的最短代碼?!?/p>


您可以嘗試的可能是:


$customer = WC()->customer;


if( ! is_a( $customer, 'WC_Customer' ) {

    global $current_user;


    if( $current_user > 0 ) { 

        $customer = new WC_Customer( $current_user->ID );

    }

}


if( is_a( $customer, 'WC_Customer' ) {

    $billing_country = $customer->get_billing_country();


    if( ! $customer->is_vat_exempt() ) {

        $customer->set_is_vat_exempt( true );

    }   

} else {

    // Some code to throw an error or debug trace

}

我希望這會解決你的問題。如果不是,您需要以某種方式將用戶 ID傳遞給您的代碼。



查看完整回答
反對 回復 2023-04-21
  • 1 回答
  • 0 關注
  • 124 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號