提问人:jacsoon jacsoon 提问时间:7/6/2023 最后编辑:ADysonjacsoon jacsoon 更新时间:7/6/2023 访问量:58
将电子邮件添加到 WooCommerce 电子邮件列表时出错 [已关闭]
Getting an error when adding an email to the WooCommerce email list [closed]
问:
我想将电子邮件添加到 WooCommerce 电子邮件列表,但收到错误。
路径:/wp-content/themes/hello-elementor-child/inc/classes/class-wsn-email.php
function add_woocommerce_emails( $emails ) {
require_once __DIR__ . '/inc/classes/class-wsn-email.php';
$emails['wsn_email'] = new WSN_Email();
return $emails;
} add_filter( 'woocommerce_email_classes', 'add_woocommerce_emails' );
路径:/wp-content/themes/hello-elementor-child/templates/email/wsn-email-template.php
路径:/wp-content/themes/hello-elementor-child/templates/email/plain/wsn-email-template.php
public function __construct() {
$this->id = 'instock_notifier_users_mailout';
$this->title = __( 'In-Stock Notifier', 'in-stock-notifier' );
$this->description = __( 'When a product is Out-of-Stock and when it comes In-Stock again, this email is sent to all users registered in the waiting list for that product.', 'in-stock-notifier' );
$this->heading = __( '{product_title} now back in stock at {blogname}', 'in-stock-notifier' );
$this->subject = __( 'A product you are waiting for is back in stock', 'in-stock-notifier' );
$this->template_base = require_once __DIR__ . '/templates/email/';
$this->template_html = 'wsn-email-template.php';
$this->template_plain = 'plain/wsn-email-template.php';
$this->customer_email = true;
add_action( 'send_wsn_email_mailout', array( $this, 'trigger' ), 10, 2 );
parent::__construct();
}
警告: require_once(C:\xampp\htdocs\ii\wp-content\themes\hello-elementor-child\inc\classes/templates/email/): 无法打开流:中没有这样的文件或目录 C:\xampp\htdocs\ii\wp-content\themes\hello-elementor-child\inc\classes\class-wsn-email.php 第 51 行
致命错误:require_once():无法打开 'C:\xampp\htdocs\ii\wp-content\themes\hello-elementor-child\inc\classes/templates/email/' (include_path='C:\xampp\php\PEAR') 在 C:\xampp\htdocs\ii\wp-content\themes\hello-elementor-child\inc\classes\class-wsn-email.php 第 51 行
问题出在哪里?
答:
若要使用子主题直接路径修复路径,可以使用该函数获取子主题目录的路径。下面是更新后的代码:get_stylesheet_directory()
function add_woocommerce_emails( $emails ) {
require_once get_stylesheet_directory() . '/inc/classes/class-wsn-email.php';
$emails['wsn_email'] = new WSN_Email();
return $emails;
}
add_filter( 'woocommerce_email_classes', 'add_woocommerce_emails' );
评论
$this->template_base = require_once get_stylesheet_directory() . '/templates/email/';
Warning: require_once(C:\xampp\htdocs\ii\wp-content\themes\hello-elementor-child\templates\email): failed to open stream: Permission denied in C:\xampp\htdocs\ii\wp-content\themes\hello-elementor-child\inc\classes\class-wsn-email.php on line 51 Fatal error: require_once(): Failed opening required 'C:\xampp\htdocs\ii/wp-content/themes/hello-elementor-child/templates/email/' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\ii\wp-content\themes\hello-elementor-child\inc\classes\class-wsn-email.php on line 51
评论
require_once
class-wsn-email.php
'C:\xampp\htdocs\ii\wp-content\themes\hello-elementor-child\inc\classes/templates/email/'