如何修复 WooCommerce PHP 致命错误:未捕获类型错误:不支持的操作数类型:字符串 – int

如果出现以下错误

PHP 致命错误:  Uncaught TypeError:Unsupported operand types: string - int in ../wp-content/plugins/woocommerce/src/Internal/Admin/WCPayPromotion/Init.php:99

该错误可能导致 WordPress 管理无法正常运行。例如,如果您进入 WordPress 块编辑器(Gutenberg),它将无法保存您的更改。等等。

问题在于 WooCommerce 与 PHP 8 的兼容性较差。幸运的是,修复方法相当简单。只需执行以下几个步骤即可解决问题:

  1. 注释 第 99 行 文件中 wp-content/plugins/woocommerce/src/Internal/Admin/WCPayPromotion/Init.php
  2. 具体如下 # $ordering[ $id ] = $is_empty ?0 : ( min( $ordering ) - 1 );
  3. 进入 WordPress 管理页面,转到 WooCommerce - 设置 - 付款
  4. 重新订购付款方式
  5. 恭喜您,您已经永久修复了致命错误,现在还可以将 WooCommerce 更新到新版本(如果有的话)。
  6. 您可以返回文件 wp-content/plugins/woocommerce/src/Internal/Admin/WCPayPromotion/Init.php 现在您可以取消对 like 99 的注释,或者保持原样......

我相信本教程一定能帮助您解决 WooCommerce 问题。一旦您来到这里,请随时 免费试用我们的 Citadela 主题.

下载 Citadela WordPress 主题和插件

立即开始无风险试用。无需信用卡。