php - 从 woocommerce 中的电子邮件模板中删除订单信息部分

标签 php wordpress woocommerce

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

enter image description here

找不到如何删除它:

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

请指教。

最佳答案

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

从所有电子邮件中删除订单详细信息的正确方法是删除其回调函数,即 WC_Emails::order_details()它被添加到 woocommerce_email_order_details hook here

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

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 中,或者最好是自定义片段插件中,例如 this one

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

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

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

关于php - 从 woocommerce 中的电子邮件模板中删除订单信息部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39251827/

相关文章:

jquery - 实现 LinkedIn 的新自动填充功能 + 请求无法完成

php - WooCommerce 在添加到购物车按钮上显示价格

php - 不应直接访问订单属性 - WooCommerce 3.0

php - 使用一列中的 ORDER BY 显示 Mysql 数据库中的数据

php - Yii2 - yii\console\Application::getSession()

php - mysql查询where条件

WordPress 休息 API : How do I append all ACF of a Post Object?

Mysql多次限制随机记录

php - WooCommerce:自动完成已付款订单

php - Laravel 包注册异常处理器