php - 发送给管理员的 WooCommerce 电子邮件通知中的自定义格式地址部分
问题描述
我已经搜索了很长时间,但由于某种原因我无法让它工作。
我只需要从管理员电子邮件中隐藏,但由于某种原因,它也适用于客户电子邮件。我想隐藏,从对方发货,以及在客户详细信息、电话和电子邮件地址中。
<?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 文件中。它应该有效。
推荐阅读
- assembly - 程序集分支/循环和函数如何工作
- entity-framework - 具有实体框架继承的 Web API
- wordpress - 按国家/地区限制 WordPress 中的某些页面
- php - 在 Woocommerce 中获取最后添加到购物车的产品 ID
- scala - Spark distinct 后跟 join 给出 IndexOutOfBoundsException
- python - 如何使用 DRF JWT 实现记住我的功能?
- javascript - 如何在文档就绪时调用 jQuery 函数?
- post - 网页抓取 - 下载 Zip 文件
- google-compute-engine - 尽管我有外部临时地址,但 gcloud 计算地址列表返回 0 个结果
- angular - “Angular 5+ 引导日期和时间选择器” - 仅限日期