我構建了一個插件,但遇到以下問題: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傳遞給您的代碼。
- 1 回答
- 0 關注
- 124 瀏覽
添加回答
舉報
0/150
提交
取消