2

我想从买家下订单后 woocommerce 发送的电子邮件模板中删除下载部分。

当他们的订单仍处于暂停、处理和退款状态时,将下载链接发送给我的买家是没有意义的。

参考下图:

在此处输入图像描述

我当前用于保留状态的电子邮件模板:

<?php
/**
 * Customer on-hold order email
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/emails/customer-on-hold-order.php.
 *
 * 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/
 * @author      WooThemes
 * @package     WooCommerce/Templates/Emails
 * @version     2.5.0
 */

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
 * @hooked WC_Emails::email_header() Output the email header
 */
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>

<p><?php _e( "Your order is on-hold until we confirm payment has been received. Your order details are shown below for your reference:", 'woocommerce' ); ?></p>

<?php
/**
 * @hooked WC_Emails::order_meta() Shows order meta data.
 */
do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email );

/**
 * @hooked WC_Emails::customer_details() Shows customer details
 * @hooked WC_Emails::email_address() Shows email address
 */
do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );

/**
 * @hooked WC_Emails::email_footer() Output the email footer
 */
do_action( 'woocommerce_email_footer', $email );

我仍然想保留订单详细信息,我只是想从电子邮件中删除下载部分。

任何帮助将不胜感激。

4

1 回答 1

1

至少因为 Woocommerce 3.2 版通常产品下载部分仅在订单状态完成或商店经理允许下载订单时才会出现。所以你的 Woocommerce 安装有问题。

现在,如果您无法解决问题,您可以做的是删除在电子邮件通知中显示产品下载部分的原始挂钩功能,并将其替换为仅在订单状态时才显示产品下载部分的类似功能完成

编码:

add_action( 'woocommerce_email', 'remove_email_order_downloads', 10, 1 );
function remove_email_order_downloads( $emails ){
    remove_action( 'woocommerce_email_order_details', array( $emails, 'order_downloads' ), 10 );
    add_action( 'woocommerce_email_order_details', 'custom_order_downloads', 9, 4 );
}

function custom_order_downloads( $order, $sent_to_admin = false, $plain_text = false, $email = '' ) {
    $show_downloads = $order->has_downloadable_item() && $order->is_download_permitted() && ! $sent_to_admin && $order->has_status('completed');

    if ( ! $show_downloads ) {
        return;
    }

    $downloads = $order->get_downloadable_items();
    $columns   = apply_filters( 'woocommerce_email_downloads_columns', array(
        'download-product' => __( 'Product', 'woocommerce' ),
        'download-expires' => __( 'Expires', 'woocommerce' ),
        'download-file'    => __( 'Download', 'woocommerce' ),
    ) );

    if ( $plain_text ) {
        wc_get_template( 'emails/plain/email-downloads.php', array( 'order' => $order, 'sent_to_admin' => $sent_to_admin, 'plain_text' => $plain_text, 'email' => $email, 'downloads' => $downloads, 'columns' => $columns ) );
    } else {
        wc_get_template( 'emails/email-downloads.php', array( 'order' => $order, 'sent_to_admin' => $sent_to_admin, 'plain_text' => $plain_text, 'email' => $email, 'downloads' => $downloads, 'columns' => $columns ) );
    }
}

代码位于您的活动子主题(或活动主题)的 function.php 文件中。测试和工作。

于 2018-07-16T13:22:37.287 回答