dqpc1845 2016-08-31 14:03
浏览 102
已采纳

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

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

enter image description here

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

Please advise.

  • 写回答

3条回答 默认 最新

  • dream518518518 2016-08-31 15:10
    关注

    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

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

    EDIT: Instructions for use

    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.

    EDIT #2: Remove Subscriptions Info Only

    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 );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教