Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WooCommerce-重命名和使用重命名的订单状态_Php_Wordpress_Woocommerce_Status_Orders - Fatal编程技术网

Php WooCommerce-重命名和使用重命名的订单状态

Php WooCommerce-重命名和使用重命名的订单状态,php,wordpress,woocommerce,status,orders,Php,Wordpress,Woocommerce,Status,Orders,我已使用此代码将订单状态“已完成”重命名为“已付款” 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-complete

我已使用此代码将订单状态“已完成”重命名为“已付款”

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' );
我的问题是,我制作了一个包含所有订单列表的页面模板:

<?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'
,而不是
'paid'

我怎样才能解决这个问题


谢谢

这是正常的,在这种情况下,您可以使用一些附加代码,创建一个函数来显示您的自定义重命名状态:

功能自定义_状态($order){
如果($order->status=='completed')
返回x('Paid','woocmerce');
其他的
返回$order->status;
}
这段代码位于活动子主题(或主题)的function.php文件或任何插件文件中

在您的模板页面中您将以以下方式使用它:


此代码经过测试并正常工作。

参考: