在Woocommerce的订单电子邮件通知中显示带和不带增值税的订单总数 [英] Display order total with and without VAT in Woocommerce's order email notification

查看:71
本文介绍了在Woocommerce的订单电子邮件通知中显示带和不带增值税的订单总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编辑订单电子邮件以添加非增值税价格!

I'm trying to edit the order email to add non-VAT price !

由于我还没有找到一种使用email-order-details.php的方式来做,而且我担心即使在子主题.php文档中也无法解决问题,因此我尝试使用我自己的代码段,工作槽function.php:

As I've not already found a way to do it the way I wanted using email-order-details.php and as I'm afraid of broking things even in a child theme .php document, I've try to do it with my own snippets, working trough function.php :

    add_action( 'woocommerce_email_after_order_table', 'add_order_email_instructions', 10, 2 );

    function add_order_email_instructions( $order, $sent_to_admin ) {
       $order_data = $order->get_data();
       $order_total = $order_data['cart_tax'];
       $order_total_tax = $order_data['total_tax'];

       if ( ! $sent_to_admin ) {
         echo '
        <!-- TABLEAU à ajouter à la suite -->
        <!-- rowspan=n dans <td …> pour prendre n colonnes et colspan=n dans <td …> pour prendre n ligne -->

    <h2>Détails de votre bon de commande </h2>
    <table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: Helvetica, Roboto, Arial, sans-serif;" border="1">
        <thead>
        <!-- Il y a 6 colonnes et autant de ligne que de <tr></tr> -->
        </thead>
      <tbody>
        <!-- Ca c est la première ligne : Les <th> sont des titres -->
            <tr>
                <th class="td" scope="col" colspan="2" style="text-align:<?php echo esc_attr( $text_align ); ?>;">Garantie Constructeur</th>
                <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;">24 mois</td>
                <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;">Incluse</td>
            </tr>
            <tr>
                <th class="td" scope="col" colspan="3" style="text-align:<?php echo esc_attr( $text_align ); ?>;">Livraison</th>
                <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;">Incluse</td>
            </tr>
            <tr>
                <th class="td" scope="col" colspan="2" style="text-align:<?php echo esc_attr( $text_align ); ?>;">Délai de fabrication</th>
                <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;">3 mois max.</td>
                <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;"></td>
            </tr>
            <tr>
                <th class="td" scope="col" colspan="2" style="text-align:<?php echo esc_attr( $text_align ); ?>;">Délai de livraison</th>
            <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;">3 semaines max.</td>
            <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;"></td>
        </tr>
       <tr>
            <th class="td" scope="col" colspan="3" style="text-align:<?php echo esc_attr( $text_align ); ?>;">Sous-total H.T.</th>
            <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;">???</td>
         </tr>
       <tr> 
    <!-- Chaque ligne de code dans un <tr> remplit chaqune des colonnes --> 
        <th class="td" scope="col" colspan="2" style="text-align:<?php echo esc_attr( $text_align ); ?>;">TVA</th>
        <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;">20 %</td>
        <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;">???*0.2</td> <!-- Sur tout les produits et options.-->
            </tr>
            <tr>
                <th class="td" scope="col" colspan="3" style="text-align:<?php echo esc_attr( $text_align ); ?>;">Total T.T.C.</th>
                <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;">???*1.2</td>
            </tr>
            <!-- -->
        </tbody>
        <tfoot>
            <!-- -->
        </tfoot>
    </table>';
        }
    }

此代码尝试用我自己的海关单元格重新创建WooCommerce生成的订单中可以看到的表:实际上,我需要带一些自定义文本的raws,然后是带小计的不带增值税的raws,然后是带有单独添加增值税,然后将原始收入加进增值税中.

This code try to recreate the table one can see in order mail generated by WooCommerce, with my own customs cells : In fact I need raws with some custom text, then a raw with the sub total without VAT, then a raw with the VAT alone, then a raw with the total with VAT include.

在我的特定示例中,我不明白为什么用<?php echo wp_kses_post( $order_total_tax ); ?> 无效代替代码中的 ??? .

In my specific exemple, I do not get why replacing ??? in my code by <?php echo wp_kses_post( $order_total_tax ); ?> doesn't work.

感谢您的帮助.

推荐答案

尝试使用

Try the following using the WC_Abstract_Order getter methods on the WC_Order object:

要获得总计(不含税),这只是一个计算:

To get the Total excluding taxes, it's just a calculation:

 $get_total_excl_taxes = $order->get_total() - $order->get_total_tax();

所以在您的代码中:

add_action( 'woocommerce_email_after_order_table', 'add_order_email_instructions', 20, 2 );
function add_order_email_instructions( $order, $sent_to_admin ) {

   if ( ! $sent_to_admin ) {
     echo '
    <!-- TABLEAU à ajouter à la suite -->
    <!-- rowspan=n dans <td …> pour prendre n colonnes et colspan=n dans <td …> pour prendre n ligne -->

<h2>Détails de votre bon de commande </h2>
<table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: Helvetica, Roboto, Arial, sans-serif;" border="1">
    <thead>
    <!-- Il y a 6 colonnes et autant de ligne que de <tr></tr> -->
    </thead>
  <tbody>
    <!-- Ca c est la première ligne : Les <th> sont des titres -->
        <tr>
            <th class="td" scope="col" colspan="2" style="text-align:<?php echo esc_attr( $text_align ); ?>;">Garantie Constructeur</th>
            <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;">24 mois</td>
            <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;">Incluse</td>
        </tr>
        <tr>
            <th class="td" scope="col" colspan="3" style="text-align:<?php echo esc_attr( $text_align ); ?>;">Livraison</th>
            <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;">Incluse</td>
        </tr>
        <tr>
            <th class="td" scope="col" colspan="2" style="text-align:<?php echo esc_attr( $text_align ); ?>;">Délai de fabrication</th>
            <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;">3 mois max.</td>
            <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;"></td>
        </tr>
        <tr>
            <th class="td" scope="col" colspan="2" style="text-align:<?php echo esc_attr( $text_align ); ?>;">Délai de livraison</th>
        <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;">3 semaines max.</td>
        <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;"></td>
    </tr>
   <tr>
        <th class="td" scope="col" colspan="3" style="text-align:<?php echo esc_attr( $text_align ); ?>;">Sous-total H.T.</th>
        <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;">'.wc_price($order->get_total() - $order->get_total_tax()).'</td>
     </tr>
   <tr>
<!-- Chaque ligne de code dans un <tr> remplit chaqune des colonnes -->
    <th class="td" scope="col" colspan="2" style="text-align:<?php echo esc_attr( $text_align ); ?>;">TVA</th>
    <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;">20 %</td>
    <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;">'.wc_price($order->get_total_tax()).'</td> <!-- Sur tout les produits et options.-->
        </tr>
        <tr>
            <th class="td" scope="col" colspan="3" style="text-align:<?php echo esc_attr( $text_align ); ?>;">Total T.T.C.</th>
            <td class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;">'.wc_price($order->get_total()).'</td>
        </tr>
        <!-- -->
    </tbody>
    <tfoot>
        <!-- -->
    </tfoot>
</table><br>';
    }
}

代码进入您的活动子主题(或活动主题)的function.php文件中.经过测试,可以正常工作.

Code goes in function.php file of your active child theme (or active theme). Tested and works.

这篇关于在Woocommerce的订单电子邮件通知中显示带和不带增值税的订单总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆