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

时间:2016-08-31 14:03:46

标签: 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; ?>

请告知。

3 个答案:

答案 0 :(得分: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或最好是自定义代码段插件,例如this one
  3. 编辑#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 );
    

答案 1 :(得分:-1)

删除此部件应修复作业  do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text );

答案 2 :(得分:-1)

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

尝试删除此挂钩。

相关问题