Woocommerce 电子邮件调试器问题

Woocommerce email debugger issue

我找到了一个用于 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以避免发送电子邮件,但没有成功。 我必须更改什么才能禁用发送功能?

谢谢

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

基本上我将 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() );