Woocommerce 电子邮件发票,通过 instance_id 的运输方式样式

问题描述

在 woocommerce 中,我有一个送货区域,在它下面有七种送货方式。送货方式 ID 为 4(本地取货)、6、7、8、9、10、10。最后六个是送货。所以首先,在本地取货时,我只想显示送货方式,而在其他情况下显示送货方式和送货地址

if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$text_align = is_rtl() ? 'right' : 'left';
$address    = $order->get_formatted_billing_address();
$shipping   = $order->get_formatted_shipping_address();

$current_shipping_method_id = '';
$current_shipping_method = '';
$type = '';

foreach($order->get_items('shipping') as $item){
    $current_shipping_method_id = $item->get_instance_id().'<br>';
}

$shipping_packages = WC()->cart->get_shipping_packages();

foreach( array_keys( $shipping_packages ) as $key ) {
    if( $shipping_for_package = WC()->session->get('shipping_for_package_'.$key) ) {
        if( isset($shipping_for_package['rates']) ) {
            foreach ( $shipping_for_package['rates'] as $rate_key => $rate ) {
                $method_id = $rate->method_id;
                $instance_id = $rate->instance_id;

                if($instance_id == 4){ // Saņemt veikalā
                    $current_shipping_method = $order->get_shipping_method();
                    $type = 4;
                }
                if($instance_id == 6){ // Piegāde darba dienās 9.00-17.00 (nesaskaņots,pēc servisa 
                vēlmēm)
                    $current_shipping_method = $order->get_shipping_method().' ('.$order->get_shipping_address_1().' '.$order->get_shipping_address_2().')';
                    $type = 6;
                }
                if($instance_id == 7){ // Piegāde darba dienās 9.00-17.00 (Saskaņots pēc klienta vēlmēm)
                    $current_shipping_method = $order->get_shipping_method().'('.$order->get_shipping_address_1().' '.$order->get_shipping_address_2().')';
                    $type = 7;
                }
                if($instance_id == 8){ // Bezmaksas piegāde
                    $current_shipping_method = $order->get_shipping_method().' ('.$order->get_shipping_address_1().' '.$order->get_shipping_address_2().')';
                    $type = 8;
                }
                if($instance_id== 9){ // Omniva pakomāts
                    $current_shipping_method = $order->get_shipping_method().' ('.$order->get_shipping_address_1().' '.$order->get_shipping_address_2().')';
                    $type = 9;
                }
                if($instance_id == 10){ // Omniva kurjers
                    $current_shipping_method = $order->get_shipping_method().' ('.$order->get_shipping_address_1().' '.$order->get_shipping_address_2().')';
                    $type = 10;
                }
                if($instance_id == 11){ // DPD pakomāts
                    $current_shipping_method = $order->get_shipping_method().' ('.$order->get_shipping_address_1().' '.$order->get_shipping_address_2().')';
                    $type = 11;
                }

            }
        }
    }
}

?>
 <div class="p2">
    <table class="table2">
        <tr>
            <th>Pasūtītājs:</td>
            <td><?PHP echo $order->get_billing_first_name().' '.$order->get_billing_last_name(); ?> 
 </td>
        </tr>
        <tr>
            <th>Kontakti:</th>
            <td>
                <a href="mailto:<?PHP echo $order->get_billing_email(); ?>"><?PHP echo esc_html( 
 $order->get_billing_email() ); ?></a>,<?PHP echo wc_make_phone_clickable( $order->get_billing_phone() ); ?>
            </td>
        </tr>
        <tr>
            <th>Preces saņemšana</th>
            <td><?PHP echo $order->get_shipping_method(); ?></td>
        </tr>
        <?PHP
        if($type == 6 || $type == 7 || $type == 8 || $type == 9 || $type == 10 || $type == 11){
        ?>
        <tr>
            <th>Saņemšanas vieta:</th>
            <td><?PHP echo $order->get_shipping_address_1().' '.$order->get_shipping_address_2(); ?> 
  </td>
        </tr>
        <?PHP
        }
        ?>
    </table>
    <?PHP echo $type; ?>
    </div>

新订单选择本地取货后,实例id 4,email显示当前实例id为4,但是$type 11为什么呢?我不明白!

解决方法

好吧,我做了不同的,但仍然不明白为什么它不能与类型方法一起使用

现在开始工作了:

<?php
        $instance_ids = array(6,7,8,9,10,11);
        if(in_array($current_shipping_method_id,$instance_ids)){
        ?>
        <tr>
            <th>Saņemšanas vieta:</th>
            <td><?php echo $order->get_shipping_address_1().' '.$order->get_shipping_address_2(); ?></td>
        </tr>
        <?php
        }
        ?>