我正在尝试通过编辑主题的functions.php文件来重命名多个WooCommerce订单状态。我发现几年前发布的一些代码可以改变单个订单状态,但由于我对php非常缺乏经验,我不知道如何扩展它以改变多个状态。理想情况下,我还想将'wc-processing'重命名为'付费',将'wc-on-hold'重命名为'待定'。
以下是我发现编辑单个订单状态的代码:
{{1}}
任何人都知道我需要做些哪些更改才能更改其他状态?
答案 0 :(得分:8)
由于存在待处理订单状态,您还需要重命名现有的"待定"状态。如果不是,您将获得2种不同的状态,并且#34;待定"标签
首先重命名这些订单状态:
add_filter( 'wc_order_statuses', 'rename_order_statuses', 20, 1 );
function rename_order_statuses( $order_statuses ) {
$order_statuses['wc-completed'] = _x( 'Order Received', 'Order status', 'woocommerce' );
$order_statuses['wc-processing'] = _x( 'Paid', 'Order status', 'woocommerce' );
$order_statuses['wc-on-hold'] = _x( 'Pending', 'Order status', 'woocommerce' );
$order_statuses['wc-pending'] = _x( 'Waiting', 'Order status', 'woocommerce' );
return $order_statuses;
}
此外,在批量修改订单列表下拉列表中:
add_filter( 'bulk_actions-edit-shop_order', 'custom_dropdown_bulk_actions_shop_order', 20, 1 );
function custom_dropdown_bulk_actions_shop_order( $actions ) {
$actions['mark_processing'] = __( 'Mark paid', 'woocommerce' );
$actions['mark_on-hold'] = __( 'Mark pending', 'woocommerce' );
$actions['mark_completed'] = __( 'Mark order received', 'woocommerce' );
return $actions;
}
这也是必需的(对于顶级菜单):
foreach( array( 'post', 'shop_order' ) as $hook )
add_filter( "views_edit-$hook", 'shop_order_modified_views' );
function shop_order_modified_views( $views ){
if( isset( $views['wc-completed'] ) )
$views['wc-completed'] = str_replace( 'Completed', __( 'Order Received', 'woocommerce'), $views['wc-completed'] );
if( isset( $views['wc-processing'] ) )
$views['wc-processing'] = str_replace( 'Processing', __( 'Paid', 'woocommerce'), $views['wc-processing'] );
if( isset( $views['wc-on-hold'] ) )
$views['wc-on-hold'] = str_replace( 'On hold', __( 'Pending', 'woocommerce'), $views['wc-on-hold'] );
if( isset( $views['wc-pending'] ) )
$views['wc-pending'] = str_replace( 'Pending', __( 'Stucked', 'woocommerce'), $views['wc-pending'] );
return $views;
}
(感谢brasofilo:Change WP admin post status filter for custom post type)
代码放在活动子主题(或活动主题)的function.php文件中。经过测试和工作。
自Woocommerce 3.3处理管理员顺序列表中的预览弹出窗口(眼睛符号):
Replace order status names everywhere incl. Woocommerce admin order preview