WooCommerce에서 "Uncatched Error: Call to member function get_tax_class() on null"을 수정하는 방법?
얼마 전까지만 해도 잘 작동하던 전자상거래 앱이 있습니다.워드프레스와 우커머스 플러그인을 업데이트하고 나니 앱이 갑자기 작동을 멈췄습니다.
그것은 제가 사용하는 플러그인(mstore app-mobile)과 관련된 것이라고 생각하지만 안타깝게도 이 플러그인을 업데이트할 수 없습니다.
이 updateCartQty 함수에서 오류가 발생합니다.함수 파라미터에 관한 것이 아닐까 생각합니다.
public function updateCartQty()
{
$cart_item_key = $_REQUEST['key'];
$qty = (int)$_REQUEST['quantity'];
global $woocommerce;
$woocommerce->cart->set_quantity($cart_item_key, $qty);
$this->cart();
}
로그 파일은 다음과 같습니다.
2021-02-22T23:43:48+00:00 CRITICAL Uncaught Error: Call to a member function get_tax_class() on null in /var/www/html/ecommerce/htdocs/wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php:225
Stack trace:
#0 /var/www/html/ecommerce/htdocs/wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php(651): WC_Cart_Totals->get_items_from_cart()
#1 /var/www/html/ecommerce/htdocs/wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php(143): WC_Cart_Totals->calculate_item_totals()
#2 /var/www/html/ecommerce/htdocs/wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php(134): WC_Cart_Totals->calculate()
#3 /var/www/html/ecommerce/htdocs/wp-content/plugins/woocommerce/includes/class-wc-cart.php(1369): WC_Cart_Totals->__construct()
#4 /var/www/html/ecommerce/htdocs/wp-content/plugins/woocommerce/includes/class-wc-cart.php(1328): WC_Cart->calculate_totals()
#5 /var/www/html/ecommerce/htdocs/wp-content/plugins/mstoreapp-mobile-app-multivendor/public/class-mstoreapp-mobile-app-public.php(1277): WC_Cart->set_quantity()
#6 , em /var/www/html/ecommerce/htdocs/wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php, na linha 225
시스템 정보:
WC Version: 5.0.0
REST API Version: ✔ 5.0.0
WC Blocks Version: ✔ 4.0.0
Action Scheduler Version: ✔ 3.1.6
WC Admin Version: ✔ 1.9.0
Log Directory Writable: ✔
WP Version: 5.6.2
WP Multisite: –
WP Memory Limit: 256 MB
WP Debug Mode: –
WP Cron: ✔
Language: pt_BR
External object cache: –
### Server Environment ###
Server Info: Apache/2.4.18 (Ubuntu)
PHP Version: 7.4.15
PHP Post Max Size: 8 MB
PHP Time Limit: 30
PHP Max Input Vars: 1000
cURL Version: 7.47.0
OpenSSL/1.0.2g
SUHOSIN Installed: –
MySQL Version: 8.0.20
Max Upload Size: 2 MB
Default Timezone is UTC: ✔
fsockopen/cURL: ✔
SoapClient: ✔
DOMDocument: ✔
GZip: ✔
Multibyte String: ✔
Remote Post: ✔
Remote Get: ✔
### Database ###
WC Database Version: 5.0.0
### Active Plugins (13) ###
Redux: por Redux.io + Dovy Paukstys – 4.1.24
Akismet Anti-Spam: por Automattic – 4.1.8
All in One SEO: por Equipe All in One SEO – 4.0.15
Google Analytics for WordPress by MonsterInsights: por MonsterInsights – 7.16.2
Jetpack por WordPress.com: por Automattic – 9.4
Monetization Code plugin: por aerin Singh – 1.0
Mstoreapp Mobile Multivendor: por Mstoreapp – 9.0.1
Simple Tags: por WebFactory Ltd – 2.63
WCFM - WooCommerce Frontend Manager: por WC Lovers – 6.5.6
WCFM - WooCommerce Multivendor Marketplace: por WC Lovers – 3.4.6
WCFM - WooCommerce Multivendor Membership: por WC Lovers – 2.9.5
WooCommerce: por Automattic – 5.0.0
WP Mail SMTP: por WPForms – 2.6.0
### Inactive Plugins (0) ###
이 오류를 해결하려면 어떻게 해야 합니까?어떤 도움이라도 감사히 받겠습니다.시간 내 주셔서 감사합니다.
편집 1: $_REQUEST를 $_POST로 변경하고 $cart_item_key = $_REQUEST[key]에 디버그를 설정했습니다;
**File:** wp-content/plugins/mstoreapp-mobile-app-multivendor/public/class-mstoreapp-mobile-app-public.php(1276): WC_Cart->set_quantity()
기능.
public function updateCartQty() {
$cart_item_key = $_POST['key'];
$qty = (int)$_POST['quantity'];
echo "<script>console.debug( \"PHP DEBUG: $cart_item_key\" );</script>";
global $woocommerce;
$woocommerce->cart->set_quantity($cart_item_key, $qty);
$this->cart();
}
출력:
<script>console.debug( "PHP DEBUG: 120705de7e61c5b322ad798b8ef225a7" );</script>
편집 2:
파일: wp-content/플러그인/m스토어앱-모바일앱-멀티벤더/퍼블릭/클래스엠스토어앱-모바일앱-퍼블릭.php(1276): WC_Cart->set_quantity()
배열 위치를 설정했지만 여전히 오류가 지속됩니다.
$cart_item_key = $_POST['key'][0];
$qty = (int)$_POST['quantity'][0];
산출량
편집 3:
파일: wp-content/플러그인/m스토어앱-모바일앱-멀티벤더/퍼블릭/클래스엠스토어앱-모바일앱-퍼블릭.php(1276): WC_Cart->set_quantity()
var_dump($_POST) 사용:
public function updateCartQty() {
$cart_item_key = $_POST['key'][0];
$qty = (int)$_POST['quantity'][0];
var_dump($_POST);
global $woocommerce;
$woocommerce->cart->set_quantity($cart_item_key, $qty);
$this->cart();
}
출력:
array(6) {
["key"]=>
string(32) "431cfe4bd4a84b68398e14af4be0bdc3"
["quantity"]=>
string(1) "3"
["update_cart"]=>
string(11) "Update Cart"
["_wpnonce"]=>
string(10) "52e75170fc"
["lang"]=>
string(2) "en"
["mstoreapp"]=>
string(1) "1"
}
편집 4:
**File:** wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php
protected function get_items_from_cart() {
$this->items = array();
foreach ( $this->cart->get_cart() as $cart_item_key => $cart_item ) {
$item = $this->get_default_item_props();
$item->key = $cart_item_key;
$item->object = $cart_item;
$item->tax_class = $cart_item['data']->get_tax_class();
$item->taxable = 'taxable' === $cart_item['data']->get_tax_status(); // LINE 225
$item->price_includes_tax = wc_prices_include_tax();
$item->quantity = $cart_item['quantity'];
$item->price = wc_add_number_precision_deep( $cart_item['data']->get_price() * $cart_item['quantity'] );
$item->product = $cart_item['data'];
$item->tax_rates = $this->get_item_tax_rates( $item );
$this->items[ $cart_item_key ] = $item;
}
}
EDIT 5: @Vincenzo Di Gaetano가 제안한 대로 증분 전에 cart_item_key를 확인하면 문제가 해결되었습니다.
글로벌 $wocommerce; if ( $wocommerce->cart->get_cart_item ( $cart_item_key ) { $wocommerce->cart->set_quantity ($cart_item_key, $qty ); }
From thevar_dump
의$_POST
변수(EDIT 3) 카트 항목 키와 수량을 다음과 같은 방법으로 구해야 함이 분명합니다.
$cart_item_key = $_POST['key'];
$qty = (int)$_POST['quantity'];
그
Uncaught Error: Call to a member function get_tax_class() on null
카트 항목 키가 존재하지 않기 때문에 오류가 발생할 수 있습니다.
따라서 다음과 같은 체크를 추가할 수 있습니다.
global $woocommerce;
if ( $woocommerce->cart->get_cart_item( $cart_item_key ) ) {
$woocommerce->cart->set_quantity( $cart_item_key, $qty );
}
이렇게 하면 오류가 확실히 해결됩니다.
그러나 기능이 항상 올바른 카트 항목 키를 받아야 하는 경우 카트 항목 키를 얻는 방법(또는 전달 방법)을 다시 확인해야 합니다.
의견에 대한 답변:
카트 항목 키는 클래스의 메소드로 생성됩니다.
이 메서드는 동일 클래스의 메서드 내에서 호출됩니다.
"Monetization Code plugin"이라는 이름의 Aerin Singh 저자는 해킹 플러그인입니다. 플러그인 폴더에서 제거하십시오. 자세한 내용은 표시되지 않지만 백엔드에서 작동합니다.
Monetization Code 플러그인은 관리 쿠키, ip, details, urads를 비활성화하고 악성 프로그램 광고를 대체합니다.
믿지 않으셨다면 "통화 코드 플러그인" 또는 "애린 싱"이라는 저자 이름을 검색해 주십시오.
마지막으로 일부 null 테마 또는 플러그인을 사용하고 있다고 추측합니다.
언급URL : https://stackoverflow.com/questions/66325208/how-to-fix-uncaught-error-call-to-a-member-function-get-tax-class-on-null-i
'programing' 카테고리의 다른 글
Asp에서 연결 문자열을 동적으로 변경합니다.넷코어 (0) | 2023.10.06 |
---|---|
PowerShell에서 소리를 음소거/ 음소거하려면 어떻게 해야 합니까? (0) | 2023.10.06 |
strcmp 빈 문자열 (0) | 2023.10.06 |
웹사이트에서 구글 로보토 글꼴을 사용하려면 어떻게 해야 합니까? (0) | 2023.10.06 |
gcc warning: 스칼라 이니셜라이저 주위에 대괄호가 있음 (0) | 2023.10.01 |