【问题标题】:Woocommerce email debugger issueWoocommerce 电子邮件调试器问题
【发布时间】:2015-05-08 01:24:02
【问题描述】:

我找到了一个用于 woocommerce 电子邮件的小调试器 (http://enru.co.uk/2014/02/17/testing-woocommerce-emails/)

它工作正常,除了一件事:我只想将其用于调试目的,目前,每次我打开电子邮件时都会发送电子邮件也是。我可以更改代码以便在不实际发送的情况下查看电子邮件吗?

我的代码是这样的:

<?php
/*
Template Name: WC_Email_Preview
*/
?>

<?php

// include WordPress' wp-load
include($_SERVER['DOCUMENT_ROOT'] . "/wp-load.php");

/*// verbose errors
ini_set('display_errors', 1);
error_reporting(E_ALL);*/

$order_id = "4452";
$email_class = $_REQUEST['email'];

if ($email_class == null) {
    $email_class = 'WC_Email_Customer_Invoice';
}

if (!isset ($order_id)) {
    global $wpdb;
    $latestOrderID = $wpdb->get_results("SELECT max(ID) as ID FROM wp_posts WHERE post_type = 'shop_order';", OBJECT);
    $order_id = $latestOrderID[0]->ID;
};

$wc_emails = new WC_Emails();
$emails = $wc_emails->get_emails();

/*$new_email = $emails[$email_class];*/
$new_email->trigger($order_id);
echo $new_email->get_content();
return;
?>

问题是,我尝试在代码末尾添加 return 以避免发送电子邮件,但没有成功。 我必须更改什么才能禁用发送功能?

谢谢

【问题讨论】:

  • 也许您应该在执行“echo $new_email->get_content()”之前返回?
  • @FlorianGerhardt 不,即使我在“echo $new_email->get_content()”之前返回,电子邮件仍然会发送
  • 可能在“$new_email->trigger(...)”之前呢?
  • 问题出在 $new_email->trigger(...) 中。这会触发电子邮件生成,然后发送。问题是,我不知道如何以及如何改变这一点。我试图在触发器之前将收件人设置为 null,但它在触发器之后发生了变化,所以我不知道该怎么做才能在不破坏默认电子邮件行为的情况下挂接到该函数

标签: php wordpress email woocommerce


【解决方案1】:

好的,我找到了一种方法。

基本上我将trigger() 函数更改为debugEmail(),并在class-wc-email-customer-invoice.php 文件中,将trigger() 复制到debugEmail() 并删除此行以避免发送电子邮件:

$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );

【讨论】:

    猜你喜欢
    • 2020-08-10
    • 2017-06-11
    • 2019-03-30
    • 1970-01-01
    • 2018-01-07
    • 2020-06-14
    • 2016-09-22
    • 2019-05-18
    • 2011-08-13
    相关资源
    最近更新 更多