在将电子邮件添加到WooCommerce电子邮件列表时出现错误。

huangapple go评论65阅读模式
英文:

Getting an error when adding an email to the WooCommerce email list

问题

问题出在以下路径:

/wp-content/themes/hello-elementor-child/inc/classes/class-wsn-email.php

具体是这一行代码引起的问题:

require_once  __DIR__ . '/inc/classes/class-wsn-email.php';

错误提示表明在打开这个文件时找不到指定的路径,因此导致了问题。

英文:

I want to add an email to the WooCommerce email list, But I get an error.

path : /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' );

path : /wp-content/themes/hello-elementor-child/templates/email/wsn-email-template.php

path : /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();
}

> Warning:
> require_once(C:\xampp\htdocs\ii\wp-content\themes\hello-elementor-child\inc\classes/templates/email/):
> failed to open stream: No such file or directory 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\inc\classes/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

where is the problem from?

答案1

得分: -2

要修复路径并使用子主题直接路径,您可以使用 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' );
英文:

To fix the path using the child theme direct path, you can use the get_stylesheet_directory() function to get the path to the child theme directory. Here's the updated code:

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' );

huangapple
  • 本文由 发表于 2023年7月6日 18:39:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76627957.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定