问题描述
我已经搜索了很长时间,但由于某种原因我无法让它工作。
我只需要隐藏管理员电子邮件,但出于某种原因,它也适用于客户电子邮件。我想隐藏,向对方发货,以及客户详细信息、电话和电子邮件地址。
<?PHP
add_filter( 'woocommerce_get_order_item_totals','custom_woocommerce_get_order_item_totals' );
function custom_woocommerce_get_order_item_totals( $totals ) {
unset( $totals['shipping'] );
return $totals;
}
///// so far is what i got to hide everything and not just the specific fields i wanted
function removing_customer_details_in_emails( $order,$sent_to_admin,$plain_text,$email ){
$wmail = WC()->mailer();
if($sent_to_admin)
remove_action( 'woocommerce_email_customer_details',array( $wmail,'email_addresses' ),20,3 );
}
add_action( 'woocommerce_email_customer_details','removing_customer_details_in_emails',5,4 );
如上所述,它也隐藏了客户电子邮件中的字段,我只需要管理员电子邮件,由于某种原因,我发现所有字段都不起作用,
解决方法
要在发送给管理员的电子邮件通知中隐藏帐单电话、帐单电子邮件和送货地址,请改用以下内容:
add_action( 'woocommerce_email_customer_details','sent_to_admin_custom_email_addresses',5,4 );
function sent_to_admin_custom_email_addresses( $order,$sent_to_admin,$plain_text,$email ){
if( in_array( $email->id,array( 'new_order','cancelled_order','failed_order' ) ) ) {
$mailer = WC()->mailer();
remove_action( 'woocommerce_email_customer_details',array( $mailer,'email_addresses' ),20 );
add_action( 'woocommerce_email_customer_details','custom_email_addresses',20,1 );
}
}
function custom_email_addresses( $order ) {
if ( is_a( $order,'WC_Order' ) ) :
$text_align = is_rtl() ? 'right' : 'left';
$address = $order->get_formatted_billing_address();
?><table id="addresses" cellspacing="0" cellpadding="0" style="width: 100%; vertical-align: top; margin-bottom: 40px; padding:0;" border="0">
<tr>
<td style="text-align:<?php echo esc_attr( $text_align ); ?>; font-family: 'Helvetica Neue',Helvetica,Roboto,Arial,sans-serif; border:0; padding:0;" valign="top" width="50%">
<h2><?php esc_html_e( 'Billing address','woocommerce' ); ?></h2>
<address class="address">
<?php echo wp_kses_post( $address ? $address : esc_html__( 'N/A','woocommerce' ) ); ?>
</address>
</td>
</tr>
</table>
<?php
endif;
}
代码位于活动子主题(或活动主题)的functions.php 文件中。它应该有效。
相关:Removing customer details and addresses from email notification templates