dongmeirang4679 2018-05-16 07:51
浏览 32

get_post_meta()在订单电子邮件(woocommerce)内部无效

I want to display the custom field value in order mail but its not showing inside the order mail while this is working with plugin(WooCommerce Email Test). Every custom field value are displaying here with this plugin.

This is my code (Inside email-order-details.php):

<tfoot>
        <?php
            if ( $totals = $order->get_order_item_totals() ) {
                $i = 0;
                foreach ( $totals as $total ) {
                    $i++;
                    ?>
                   <?php if($total['label'] == "Shipping:" || $total['label'] == "Verzending:"){ ?>

                   <?php } elseif($total['label'] == "Subtotal:" || $total['label'] == "Subtotaal:") {
                   $oid = $order->get_id(); ?>
                   <tr>
                        <th class="td" scope="row" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo "Subtotaal"; ?></th>
                        <td class="td" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php $order_st=get_post_meta($oid, 'order_subtotal', true); echo "<span class='woocommerce-Price-currencySymbol'>".get_woocommerce_currency_symbol()."</span>".$order_st."245.00"; ?></td>
                    </tr>
                    <?php $trans_method=get_post_meta($oid, 'trans_method', true); if($trans_method == 'pickup'){ ?>
                    <tr>
                        <th class="td" scope="row" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo "Transportkosten"; ?></th>
                        <td class="td" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo "<span class='woocommerce-Price-currencySymbol'>".get_woocommerce_currency_symbol()."</span>0.00"; ?></td>
                    </tr>
                    <tr>
                        <td colspan="2" class="td" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo "Afhalen"; ?></td>
                    </tr>
                    <tr>
                        <th class="td" scope="row" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo "Totaal ex BTW"; ?></th>
                        <td class="td" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php $teb=get_post_meta($oid, 'order_subtotal', true); echo "<span class='woocommerce-Price-currencySymbol'>".get_woocommerce_currency_symbol()."</span>".$teb; ?></td>
                    </tr>
                    <?php } ?>
                    <?php if($trans_method == 'deliverybypostcode'){ ?>
                    <tr>
                        <th class="td" scope="row" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo "Transportkosten"; ?></th>
                        <td class="td" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><span class="woocommerce-Price-currencySymbol"><?php $transcost=get_post_meta($oid, 'tran_cost', true); echo get_woocommerce_currency_symbol();  ?></span><?php echo money_format("%.2n", $transcost); ?></td>
                    </tr>
                    <tr><td colspan="2" class="td" scope="row" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo "Bezorgen op postcode:"; ?> <?php $postcode=get_post_meta($oid, 'trans_location', true);
                    $place_dis=get_post_meta($oid, 'trans_distance', true);
                    $mcrane=get_post_meta($oid, 'mounted_crane', true);
                     echo $postcode[0]." ".$place_dis."</br>";
    if($mcrane == "Yes"){
        echo "Transport: "."Met autolaadkraan"."</td></tr>";
    }else{
        echo "Transport: "."Zonder autolaadkraan"."</td></tr>";
    } ?>
    <tr>
                        <th class="td" scope="row" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo "Totaal ex BTW"; ?></th>
                        <td class="td" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php $os_total=get_post_meta($oid, 'order_subtotal', true);
                         $tcost=get_post_meta($oid, 'tran_cost', true);
                        $ot_cost=$os_total+money_format("%.2n", $tcost);
                          echo "<span class='woocommerce-Price-currencySymbol'>".get_woocommerce_currency_symbol()."</span>". money_format("%.2n", $ot_cost); ?></td>
                    </tr>
    <?php } ?>
                   <?php } elseif($total['label'] == "BTW:"){ 
                    $oid1 = $order->get_id();
                    ?>
                   <tr>
                        <th class="td" scope="row" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo $total['label']; ?></th>
                        <td class="td" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php $ttax = get_post_meta($oid1, 'order_total_tax', true); echo "<span class='woocommerce-Price-currencySymbol'>".get_woocommerce_currency_symbol()."</span>".$ttax; ?></td>
                    </tr>
                     <?php } elseif($total['label'] == "Total:" || $total['label'] == "Totaal:"){ ?>
                     <tr>
                        <th class="td" scope="row" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo "Totaal incl. BTW"; ?></th>
                        <td class="td" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo $total['value']; ?></td>
                    </tr>
                   <?php }else{ ?>
                    <tr>
                        <th class="td" scope="row" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo $total['label']; ?></th>
                        <td class="td" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo $total['value']; ?></td>
                    </tr><?php }
                }
            }
        ?>
    </tfoot>

Please tell me what thing I am doing wrong here (Simply I just want to display custom fields value also inside order mail)

  • 写回答

1条回答 默认 最新

  • dqcj32855 2018-05-31 05:23
    关注

    Actually, I was updating my custom values ​​on Thank You page due to which our custom value was updated in the database after sending the order email.

    Therefore i am was not getting the custom value in the order mail.

    Now I updated Our custom value before sending the order mail and it's working fine.

    Thank's Guys for your response!

    评论

报告相同问题?

悬赏问题

  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景