繁体   English   中英

删除 woocommerce email 通知中的产品下载部分

[英]Remove product downloads section in woocommerce email notifications

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

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

参考下图:

在此处输入图像描述

我当前的 email 暂停状态模板:

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

我仍然想保留订单详情,我只是想从 email 中删除下载部分。

任何帮助将不胜感激。

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

现在,如果您无法解决问题,您可以做的是删除原来在 email 通知中显示产品下载部分的钩子 function,并将其替换为类似的,仅在订单状态时才允许显示产品下载部分完成了

代码:

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 文件。 测试和工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM