WooCommerce - 重命名和使用重命名的订单状态 [英] WooCommerce - Renaming and using renamed order status
本文介绍了WooCommerce - 重命名和使用重命名的订单状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用此代码将我的订单状态已完成"重命名为已付款"
I've already renamed my order status 'completed' to 'paid' using this code
function wc_renaming_order_status( $order_statuses ) {
foreach ( $order_statuses as $key => $status ) {
$new_order_statuses[ $key ] = $status;
if ( 'wc-completed' === $key ) {
$order_statuses['wc-completed'] = _x( 'Paid', 'Order status', 'woocommerce' );
}
}
return $order_statuses;
}
add_filter( 'wc_order_statuses', 'wc_renaming_order_status' );
我的问题是我做了一个包含我所有订单列表的页面模板:
My problem is that I did a page template with a list of all my orders:
<?php
while ( $loop->have_posts() ) : $loop->the_post();
$order_id = $loop->post->ID;
$order = new WC_Order($order_id);
?>
<tr>
<td style="text-align:left;"><?php echo $order->get_order_number(); ?></td>
<td style="text-align:left;"><?php echo $order->billing_first_name; ?>
<?php echo $order->billing_last_name; ?></td>
<td style="text-align:left;"><?php echo $order->billing_company; ?></td>
<td style="text-align:left;"><?php echo $order->status; ?></td>
</tr>
<?php endwhile; ?>
并且 $order->status
仍然返回 'completed'
而不是 <代码>'付费'.
And the $order->status
still returns 'completed'
instead of 'paid'
.
我该如何解决这个问题?
How can I solve this problem?
谢谢
推荐答案
这是正常现象,您可以使用一些额外的代码,创建一个函数来显示您自定义的重命名状态:
This is normal and your this specific case you could use some additional code, creating a function to display your custom renamed status:
function custom_status($order){
if($order->status == 'completed')
return _x( 'Paid', 'woocommerce' );
else
return $order->status;
}
此代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中.
在您的模板页面中,您将这样使用它:
In your template page you will use it this way:
<?php
while ( $loop->have_posts() ) : $loop->the_post();
$order_id = $loop->post->ID;
$order = new WC_Order($order_id);
?>
<tr>
<td style="text-align:left;"><?php echo $order->get_order_number(); ?></td>
<td style="text-align:left;"><?php echo $order->billing_first_name; ?>
<?php echo $order->billing_last_name; ?></td>
<td style="text-align:left;"><?php echo $order->billing_company; ?></td>
<td style="text-align:left;"><?php echo custom_status($order); ?></td>
</tr>
<?php endwhile; ?>
此代码已经过测试且有效.
这篇关于WooCommerce - 重命名和使用重命名的订单状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文