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>

在new order之后,它被选择为local pick, instance id 4,在邮件中显示当前实例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
}
?>

最新更新