我有一个电子商务应用程序,前几天还能正常工作。在我更新了wordpress和woocommerce插件后,应用程序突然停止工作了。
我认为这是关于我使用的插件(mstore应用程序移动),但不幸的是不可能更新这个插件.
错误发生在这个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>
型
x1c 0d1x的数据
编辑2:
**文件:**wp-content/plugins/mstoreapp-mobile-app-multivendor/public/class-mstoreapp-mobile-app-public.php(1276):WC_Cart->set_quantity()
我已经设置了数组位置,但错误仍然存在:
$cart_item_key = $_POST['key'][0];
$qty = (int)$_POST['quantity'][0];
型
的
输出
的
编辑3:
**文件:**wp-content/plugins/mstoreapp-mobile-app-multivendor/public/class-mstoreapp-mobile-app-public.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;
}
}
**编辑5:**如@ Crienzo Di Gaetano所建议的,在增量之前检查cart_item_key已经解决了这个问题。
全球$woocommerce; if($woocommerce->cart->get_cart_item($cart_item_key)){ $woocommerce->cart->set_quantity($cart_item_key,$qty); }
2条答案
按热度按时间c8ib6hqw1#
从
$_POST
变量的var_dump
**(编辑3)**中可以清楚地看到,您必须以这种方式获取购物车项目键和数量:字符串
Uncaught Error: Call to a member function get_tax_class() on null
错误可能是由于购物车项目键不存在。所以你可以像这样添加一个检查:
型
这肯定会修复错误。
然而,如果你的函数总是得到正确的购物车项目键,你需要仔细检查你是如何得到(或如何传递)购物车项目键的。
对您的评论的回答:
购物车商品键由
WC_Cart
类的generate_cart_id()
方法生成。此方法在同一个
WC_Cart
类的**add_to_cart
**方法中调用。enxuqcxy2#
艾林辛格作者命名为“货币化代码插件“是一个黑客插件,请将其从您的插件文件夹中删除它不会显示的细节,但它会在后端工作.
货币化代码插件需要管理员cookie,IP,详细信息,并禁用UR广告和替换他们的恶意软件广告.
如果你不相信,请搜索名称“货币化代码插件”或作者姓名“艾琳辛格”。
最后,我猜你正在使用一些无效的主题或插件