从woocommerce中的电子邮件模板中删除订单信息部分 [英] Delete order info section from email template in woocommerce

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

问题描述

我正在尝试删除已完成订单和客户发票电子邮件中的订单信息部分.

I'm trying to delete the Order Information section on a Completed Order and Customer Invoice emails.

在以下位置找不到如何删除它:

Can't find how to delete this in the:

wp-content/plugins/woocommerce/templates/emails/customer-completed-order.php


<?php
/**
 * Subscription information template
 *
 * @author  Brent Shepherd / Chuck Mac
 * @package WooCommerce_Subscriptions/Templates/Emails
 * @version 1.5
 */
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}
?>
<?php if ( ! empty( $subscriptions ) ) : ?>
<h2><?php esc_html_e( 'Order Information:', 'woocommerce-subscriptions' ) ?></h2>
<table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">
    <thead>
        <tr>
            <th scope="col" style="text-align:left; border: 1px solid #eee;"><?php esc_html_e( 'Order', 'woocommerce-subscriptions' ); ?></th>
            <th scope="col" style="text-align:left; border: 1px solid #eee;"><?php esc_html_e( 'Start Date', 'woocommerce-subscriptions' ); ?></th>
            <th scope="col" style="text-align:left; border: 1px solid #eee;"><?php esc_html_e( 'End Date', 'woocommerce-subscriptions' ); ?></th>
            <th scope="col" style="text-align:left; border: 1px solid #eee;"><?php esc_html_e( 'Price', 'woocommerce-subscriptions' ); ?></th>
        </tr>
    </thead>
    <tbody>
    <?php foreach ( $subscriptions as $subscription ) : ?>
        <tr>
            <td scope="row" style="text-align:left; border: 1px solid #eee;"><a href="<?php echo esc_url( ( $is_admin_email ) ? wcs_get_edit_post_link( $subscription->id ) : $subscription->get_view_order_url() ); ?>"><?php echo esc_html( $subscription->get_order_number() ); ?></a></td>
            <td scope="row" style="text-align:left; border: 1px solid #eee;"><?php echo esc_html( date_i18n( wc_date_format(), $subscription->get_time( 'start', 'site' ) ) ); ?></td>
            <td scope="row" style="text-align:left; border: 1px solid #eee;"><?php echo esc_html( ( 0 < $subscription->get_time( 'end' ) ) ? date_i18n( wc_date_format(), $subscription->get_time( 'end', 'site' ) ) : __( 'When Cancelled', 'woocommerce-subscriptions' ) ); ?></td>
            <td scope="row" style="text-align:left; border: 1px solid #eee;"><?php echo wp_kses_post( $subscription->get_formatted_order_total() ); ?></td>
        </tr>
    <?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>

请告知.

推荐答案

您不想删除整个动作挂钩.这可能会影响其他依赖于它的存在的插件. (更不用说订单详细信息在woocommerce_email_order_details详细信息钩子上,而不是woocommerce_email_order_meta钩子上.)

You don't want to remove the entire action hook. This could effect other plugins that rely on it's presence. (Not to mention the order details are on the woocommerce_email_order_details details hook and not the woocommerce_email_order_meta hook anyway).

从所有电子邮件中删除订单详细信息的正确方法是删除其回调函数,即

The proper way to remove the order details from all emails is to remove their callback function which is WC_Emails::order_details() which is added to the woocommerce_email_order_details hook here

您不能直接调用remove_action(),因此必须从add_action()回调内部进行调用...在将其添加到钩子之后但在运行之前.在这种情况下,我们将潜入同一个钩子,但优先级更高.另请注意,remove_action()必须具有与您要删除的add_action()相同的优先级.

You cannot call remove_action() directly and so must call it from inside an add_action() callback... after it has been added to it's hook, but before it has been run. In this case we're just going to sneak onto the same hook, but with an earlier priority. Also note, that remove_action() must have the same priority as the add_action() that you are trying to remove.

function so_39251827_remove_order_details( $order, $sent_to_admin, $plain_text, $email ){
    $mailer = WC()->mailer(); // get the instance of the WC_Emails class
    remove_action( 'woocommerce_email_order_details', array( $mailer, 'order_details' ), 10, 4 );
}
add_action( 'woocommerce_email_order_details', 'so_39251827_remove_order_details', 5, 4 );

使用说明

  1. 停止覆盖emails/customer-completed-order.php模板,并将其从您的主题中删除.您无需直接编辑即可解决此问题.
  2. 将上述代码块添加到主题的functions.php或最好是自定义代码段插件中,例如这个.
  1. Stop overriding the emails/customer-completed-order.php template and remove it from your theme. You do not need to edit it directly to solve this question.
  2. Add the above code block to your theme's functions.php or preferably a custom-snippets plugin, such as this one.

编辑#2:删除仅订阅信息

将上面的代码替换为以下内容:

Replace the above code with the following:

function so_39251827_remove_subscription_details( $order, $sent_to_admin, $plain_text, $email ){
    remove_action( 'woocommerce_email_after_order_table', array( 'WC_Subscriptions_Order', 'add_sub_info_email' ), 15, 3 );
}
add_action( 'woocommerce_email_after_order_table', 'so_39251827_remove_subscription_details', 5, 4 );

这篇关于从woocommerce中的电子邮件模板中删除订单信息部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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