如何隐藏增值税标签和价值从WooCommerce订单电子邮件


How to hide VAT label and value from WooCommerce order emails?

我想从WooCommerce订单电子邮件中隐藏或删除增值税(税)行。结果从"get_order_item_totals()"函数中得到。我已经可以通过使用以下代码隐藏电子邮件的税务标签。

function sv_change_email_tax_label( $label ) {
    $label = '';
    return $label;
}
add_filter( 'woocommerce_countries_tax_or_vat', 'sv_change_email_tax_label'       );

我想从订单电子邮件中隐藏整行增值税。

终于想出了一个办法。"get_order_item_totals()"函数返回一个数组的数组。所以我将不需要的数组unset()。在这种情况下$合计[税]以下是我的代码在电子邮件模板。

<?php
    if ( $totals = $order->get_order_item_totals() ) {              
       unset($totals[tax]);
       $i = 0;
       foreach ( $totals as $total ) {                  
       $i++;                    
     ?><tr>
       <th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th>
       <td style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td>
</tr><?php                  
      }
   }
 ?>

非常感谢每个试图帮助你的人!的问候!

根据订单的状态,您需要编辑相关的电子邮件模板。

例如:如果您启用了货到付款方式,并且客户选择了该选项,则订单状态将为"处理中",在这种情况下,您需要编辑customer-processing-order.php模板。

//find this line and after it add the following line of code                
foreach ( $totals as $total ) {  
    //ensure to change "VAT" with the label that appears on your email
    if( strstr( $total['label'], "VAT" ) )  continue;