所以我试图为我的woocommerce商店创建一个自定义电子邮件,我可以使用作为付款提醒.我把所有东西放在一起如下:一个“custom-payment-payder.php”文件,内容如下:
<?php
/**
* Payment reminder Email
*
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce\Templates\Emails
* @version 3.7.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class WC_Custom_Payment_Reminder_Email extends WC_Email {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'custom_payment_reminder';
$this->title = __('Payment Reminder', 'your-textdomain');
$this->description = __('This is a custom payment reminder email.', 'your-textdomain');
$this->template_html = 'emails/custom-payment-reminder-html.php';
$this->template_plain = 'emails/plain/payment-reminder.php';
// Call parent constructor
parent::__construct();
// Other settings like 'enabled', 'recipient', etc. can be added here
}
public function get_default_subject() {
return __( 'Zahlungserinnerung Ihrer Bestellung #{order_number} bei {site_url}' );
}
/**
* Trigger function to send the custom payment reminder email.
*
* @param int $order_id Order ID.
*/
public function trigger($order_id) {
// Get the order object
$order = wc_get_order($order_id);
// Set the email recipient(s)
if ( is_a( $order, 'WC_Order' ) ) {
$this->object = $order;
$this->recipient = $order->get_billing_email();
$this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
$this->placeholders['{order_number}'] = $this->object->get_order_number();
}
// Optionally, you can set additional email headers or parameters
$this->send($this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments());
}
/**
* Get content html.
*
* @return string
*/
public function get_content_html() {
return wc_get_template_html(
$this->template_html,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
}
字符串
然后,我把一个html模板的电子邮件在我的子主题在woopage/emails/custom-payment-payder-html.php”。该文件的内容不应该是重要的这个问题,因为它是在两种情况下相同的。
接下来,我在我的functions.php中放入以下行:
add_filter('woocommerce_email_classes', 'add_custom_email_class');
function add_custom_email_class($email_classes) {
require_once(get_stylesheet_directory() . '/woocommerce/emails/custom-payment-reminder.php');
// Add your custom email class
$email_classes['WC_Custom_Payment_Reminder_Email'] = new WC_Custom_Payment_Reminder_Email();
return $email_classes;
}
型
如果我检查woocommerce ->设置->电子邮件,我可以找到模板,当我点击它时,我可以配置它,并在底部的“html模板”下显示html模板的路径。
现在问题来了:我在plugin文件夹中创建了一个文件夹,并创建了一个包含functions.php中的行的新文件我将custom-payment-payder.php文件移动到包含该插件文件夹的文件夹中,并将html模板文件的路径更改为:$this->template_html = get_stylesheet_directory() . '/woocommerce/emails/custom-payment-reminder-html.php';
激活插件后,邮件再次在woocommerce设置下显示正常,但当点击它时,在底部的“html模板”它说**“文件未找到”.**
我尝试更改html模板文件的路径,但由于某种原因仍然找不到模板文件。有人知道在哪里查找错误吗?提前感谢!
更新:如果从插件,我加载的文件与电子邮件类从子主题目录,它的作品!现在的问题是为什么?我可能是一些关于路径的html模板,但我不能找出问题是什么:-(它可能需要指定相对于文件调用它?
将功能从functions.php移到一个单独的plugin.php文件不再起作用
1条答案
按热度按时间vltsax251#
我想我刚刚找到了解决方案:模板库需要像这样设置(最后一行):
字符串
现在它实际上工作了!我不明白,为什么它不工作与绝对路径,我以前使用。