You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在WooCommerce邮件模板中获取订单收件人并按条件隐藏价格行

Solution: Hide Product Price Rows in WooCommerce Email Based on Recipient

First, let’s make sure you don’t lose your customizations when WooCommerce updates: copy the email-order-details.php file from wp-content/plugins/woocommerce/templates/emails/ to your theme’s woocommerce/emails/ directory (create the subfolders if they don’t exist). This way, your changes stay intact through plugin updates.

Step 1: Grab the Email Recipient in the Template

At the top of your copied email-order-details.php file (or right before the order items loop), add this line to fetch the current email recipient:

// Get the recipient of this email
$email_recipient = $email->recipient;

Step 2: Hide the Price Column in the Table Header

Look for the table header row that includes the "Price" (or "Subtotal") column. Wrap that <th> element in a conditional check to only show it if the recipient is test@test.com:

<?php if ( $email_recipient === 'test@test.com' ) : ?>
<th class="td" scope="col" style="text-align:left; border: 1px solid #eee; border-bottom-width: 4px; padding: 12px; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;"><?php esc_html_e( 'Price', 'woocommerce' ); ?></th>
<?php endif; ?>

Step 3: Hide Price Rows for Individual Products

Next, find the section inside the foreach ( $order->get_items() as $item_id => $item ) loop where each product’s price is displayed. Wrap the price <td> element in the same conditional check:

<?php if ( $email_recipient === 'test@test.com' ) : ?>
<td class="td" style="text-align:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" colspan="2">
	<?php echo $order->get_formatted_line_subtotal( $item ); ?>
</td>
<?php endif; ?>

Quick Notes:

  • If your template uses a separate column for quantity and subtotal, adjust the conditional wrap to target the correct price-related elements.
  • For case-insensitive email matching (e.g., if recipients might use Test@Test.com), use strtolower( $email_recipient ) === strtolower( 'test@test.com' ) instead.
  • This method leverages the $email object that’s already available in WooCommerce email templates, so you don’t need extra hooks to get the recipient.

内容的提问来源于stack exchange,提问作者Benny

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 17:27:34