微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

enter image description here

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

wp-content/plugins/woocommerce/templates/emails/customer-completed-order.PHP
<?PHP
/**
 * Subscription @R_691_4045@ion 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 @R_691_4045@ion:', '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挂钩).

从所有电子邮件删除订单详细信息的正确方法删除其回调函数,该函数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 );

编辑:使用说明

>停止覆盖电子邮件/ customer-completed-order.PHP模板并将其从主题删除.您无需直接编辑即可解决此问题.
>将以上代码添加主题的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 );

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐