我测试了很多WooCommerce版本(3.3.x、3.4.x和3.5.x),使用WP Rollback 我相信这是3.5.2版中修复的电子邮件模板中的一个错误。我在变更日志中找不到任何与此相关的内容:https://raw.githubusercontent.com/woocommerce/woocommerce/master/CHANGELOG.txt
以下是WooCommerce版本3.5.2中的模板:
我必须进行更深入的调查才能知道是什么,但3.5.2以下的版本会引发此错误:
[11-Jun-2019 13:46:09 UTC] PHP Warning: preg_replace(): Compilation failed: invalid range in character class at offset 39 in C:\\xampp\\htdocs\\market\\wp-content\\plugins\\woocommerce\\includes\\libraries\\class-emogrifier.php on line 1504
[11-Jun-2019 13:46:09 UTC] PHP Stack trace:
[11-Jun-2019 13:46:09 UTC] PHP 1. {main}() C:\\xampp\\htdocs\\market\\wp-admin\\index.php:0
[11-Jun-2019 13:46:09 UTC] PHP 2. require_once() C:\\xampp\\htdocs\\market\\wp-admin\\index.php:10
[11-Jun-2019 13:46:09 UTC] PHP 3. do_action() C:\\xampp\\htdocs\\market\\wp-admin\\admin.php:156
[11-Jun-2019 13:46:09 UTC] PHP 4. WP_Hook->do_action() C:\\xampp\\htdocs\\market\\wp-includes\\plugin.php:453
[11-Jun-2019 13:46:09 UTC] PHP 5. WP_Hook->apply_filters() C:\\xampp\\htdocs\\market\\wp-includes\\class-wp-hook.php:310
[11-Jun-2019 13:46:09 UTC] PHP 6. WC_Admin->preview_emails() C:\\xampp\\htdocs\\market\\wp-includes\\class-wp-hook.php:286
[11-Jun-2019 13:46:09 UTC] PHP 7. WC_Email->style_inline() C:\\xampp\\htdocs\\market\\wp-content\\plugins\\woocommerce\\includes\\admin\\class-wc-admin.php:210
[11-Jun-2019 13:46:09 UTC] PHP 8. Emogrifier->emogrify() C:\\xampp\\htdocs\\market\\wp-content\\plugins\\woocommerce\\includes\\emails\\class-wc-email.php:530
[11-Jun-2019 13:46:09 UTC] PHP 9. Emogrifier->createAndProcessXmlDocument() C:\\xampp\\htdocs\\market\\wp-content\\plugins\\woocommerce\\includes\\libraries\\class-emogrifier.php:291
[11-Jun-2019 13:46:09 UTC] PHP 10. Emogrifier->process() C:\\xampp\\htdocs\\market\\wp-content\\plugins\\woocommerce\\includes\\libraries\\class-emogrifier.php:327
[11-Jun-2019 13:46:09 UTC] PHP 11. Emogrifier->translateCssToXpath() C:\\xampp\\htdocs\\market\\wp-content\\plugins\\woocommerce\\includes\\libraries\\class-emogrifier.php:369
[11-Jun-2019 13:46:09 UTC] PHP 12. Emogrifier->translateCssToXpathPass() C:\\xampp\\htdocs\\market\\wp-content\\plugins\\woocommerce\\includes\\libraries\\class-emogrifier.php:1448
[11-Jun-2019 13:46:09 UTC] PHP 13. Emogrifier->translateCssToXpathPassWithMatchClassAttributesCallback() C:\\xampp\\htdocs\\market\\wp-content\\plugins\\woocommerce\\includes\\libraries\\class-emogrifier.php:1472
[11-Jun-2019 13:46:09 UTC] PHP 14. preg_replace() C:\\xampp\\htdocs\\market\\wp-content\\plugins\\woocommerce\\includes\\libraries\\class-emogrifier.php:1504
感谢@SallyCJ的耐心和支持!
<小时>
Workaround:
我得到了3.5.2的课程,并在我的主题中使用了该课程。因此,您将能够修复WooCommerce 3.5.1及更低版本中的错误:
//3.4.7
add_filter( \'woocommerce_email_classes\', function($emails){
require_once get_template_directory() . \'/class-emogrifier.php\';
return $emails;
});
//3.5.1
add_filter( \'woocommerce_email_styles\', function($style){
require_once get_template_directory() . \'/class-emogrifier.php\';
return $style;
});
Class Emogrifier v2.0.0:
https://pastebin.com/U0eAFXpx