【问题标题】:Delete order info section from email template in woocommerce从 woocommerce 中的电子邮件模板中删除订单信息部分
【发布时间】:2021-08-08 16:26:51
【问题描述】:

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

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

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

请指教。

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

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

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

    您不能直接调用remove_action(),因此必须在add_action() 回调中调用它...在它被添加到它的钩子之后,但在它运行之前。在这种情况下,我们将潜入同一个钩子,但具有更早的优先级。另请注意,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 或最好是自定义sn-ps 插件,例如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 );
    

    【讨论】:

    • 你好,我删除了do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email ); 订单信息表被删除了,但订单表也被删除了。我想保留订单表 - 我怎样才能保留它并只删除订单信息表?请指教。
    • 不要删除整个钩子。正如我所解释的,这将删除附加到钩子的 all 动作。请使用我提供的代码。
    • 嗨 - 对不起,我误解了 - 我已经插入了我存档的代码并更新了原始问题。您能否解释一下我需要删除或添加/替换哪些部分 - 我没有太多编程技能 - 感谢您的帮助。
    • 从您的主题中删除整个emails/customer-completed-order.php。您确实不需要覆盖此模板。你只需要我提供的代码。请参阅我的编辑以获取更清晰的使用说明。
    • 嗨,emails/customer-completed-order.php 不存在于我的主题文件夹中,我只有在这里:wp-content/plugins/woocommerce/templates/emails/customer-completed-order.php 我下载了代码 sn-p 插件并将您的代码添加到其中 - 它已删除两个订单表。请告知 - 非常感谢您在这里的帮助。
    【解决方案2】:

    删除这部分应该可以解决问题
    do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text );

    【讨论】:

    • 嗨,整行是:do_action('woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email);我要删除这个吗?
    【解决方案3】:

    do_action('woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text);

    尝试移除这个钩子。

    【讨论】:

    • 嗨,整行是:do_action('woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email);我要删除这个吗?
    • 订单详情不在此钩子上。当您只需要删除添加到钩子的操作时,删除整个钩子是一个坏主意。
    猜你喜欢
    • 2019-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-24
    • 1970-01-01
    • 1970-01-01
    • 2018-10-17
    • 1970-01-01
    相关资源
    最近更新 更多