删除 woocommerce 电子邮件通知中的产品下载部分 [英] Remove product downloads section in woocommerce email notifications

查看:29
本文介绍了删除 woocommerce 电子邮件通知中的产品下载部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to remove the download section from the email template that woocommerce will send after my buyer has placed an order.

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

It doesn’t make sense to send the download link to my buyer when their order is still on hold, processing and refunded state.

参考下图:

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

my current email template for on hold status:

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

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

I still want to retain the order details, I just wanted to remove the download section from the email.

任何帮助将不胜感激.

推荐答案

至少从 Woocommerce 3.2 版开始,产品下载部分通常仅在订单状态完成或商店经理允许下载订单时出现.所以您的 Woocommerce 安装有问题.

At least since Woocommerce version 3.2 normally products downloads section only appears when order status is completed or when shop manager allows downloads for the order. So there is something wrong in your Woocommerce installation.

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

Now what you can do if you can't solve the problem, is to remove the original hooked function that displays the products downloads section in email notification and replace it with a similar one that will allow to display the products downloads section only when order status is completed.

代码:

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 文件中.经测试有效.

Code goes in function.php file of your active child theme (or active theme). Tested and works.

这篇关于删除 woocommerce 电子邮件通知中的产品下载部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆