将电子邮件添加到 WooCommerce 电子邮件列表时出错 [已关闭]

Getting an error when adding an email to the WooCommerce email list [closed]

提问人:jacsoon jacsoon 提问时间:7/6/2023 最后编辑:ADysonjacsoon jacsoon 更新时间:7/6/2023 访问量:58

问:


想改进这个问题吗?通过编辑这篇文章添加详细信息并澄清问题。

5个月前关闭。

我想将电子邮件添加到 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 行

问题出在哪里?

php wordpress 电子邮件 woocommerce

评论

0赞 Bhautik 7/6/2023
错误消息表明您尝试需要的文件或目录不存在。请确保语句中指定的文件或目录路径正确无误。在代码中,错误发生在文件的第 51 行。检查路径是否正确,以及文件或目录是否存在。如果文件或目录不存在,则需要创建它或将路径更新到正确的位置。require_onceclass-wsn-email.php'C:\xampp\htdocs\ii\wp-content\themes\hello-elementor-child\inc\classes/templates/email/'
0赞 jacsoon jacsoon 7/6/2023
嗨 Bhautik,感谢您的解释,但我意识到这是因为错误的路径,但是如何调用正确的路径,我的文件在模板子中,如您所见,我指定了文件的路径并根据它们的路径调用了文件。

答:

-2赞 Bhautik 7/6/2023 #1

若要使用子主题直接路径修复路径,可以使用该函数获取子主题目录的路径。下面是更新后的代码: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' );

评论

0赞 jacsoon jacsoon 7/6/2023
我这样做了,我也这样做了:,我遇到了一个新错误:$this->template_base = require_once get_stylesheet_directory() . '/templates/email/';
0赞 jacsoon jacsoon 7/6/2023
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
0赞 Bhautik 7/6/2023
错误消息表明在给定路径中打开文件时存在权限问题。要解决此问题,您需要确保文件和目录设置了正确的权限。
0赞 jacsoon jacsoon 7/6/2023
在其他插件中,我看到电子邮件模板文件夹具有相同的访问级别,但没有问题。
0赞 DavidW 7/8/2023
这很可能是 ChatGPT(评论也看起来像 ChatGPT)