"manual" Woocommerce 自定义订单状态的奇怪显示样式
Strange displayed style for "manual" Woocommerce custom order status
我正在使用以下代码为 Woocommerce 创建新的自定义订单状态。我遇到的问题是,在管理员中,状态显示为无样式。如何以类似于“正在处理”的方式设置自定义状态的样式?
/* Adding a new custom order status */
function register_manual_order_status() {
register_post_status( 'wc-manual', array(
'label' => 'Manual Order',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Manual order (%s)', 'Manual order (%s)' )
) );
}
add_action( 'init', 'register_manual_order_status' );
// Add to list of WC Order statuses
function add_manual_to_order_statuses( $order_statuses ) {
$new_order_statuses = array();
// add new order status after processing
foreach ( $order_statuses as $key => $status ) {
$new_order_statuses[ $key ] = $status;
if ( 'wc-processing' === $key ) {
$new_order_statuses['wc-manual'] = 'Manual';
}
}
return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_manual_to_order_statuses' );
不要使用 wc-manual
slug,因为 manual
slug 已在 WooCommerce 中保留并显示箭头。而是将您的状态标签更改为 wc-manual-order
,箭头将根据需要替换为状态名称。
因此您的代码将是:
// Add a custom order status
add_action( 'init', 'register_manual_order_status' );
function register_manual_order_status() {
register_post_status( 'wc-manual-order', array(
'label' => __('Manual Order'),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Manual order (%s)', 'Manual order (%s)' )
) );
}
// Add Custom order status after processing on order statuses dropdown
add_filter( 'wc_order_statuses', 'add_manual_to_order_statuses' );
function add_manual_to_order_statuses( $order_statuses ) {
$new_order_statuses = array();
foreach ( $order_statuses as $key => $status ) {
$new_order_statuses[ $key ] = $status;
if ( 'wc-processing' === $key ) {
$new_order_statuses['wc-manual-order'] = __('Manual');
}
}
return $new_order_statuses;
}
代码进入活动子主题(或活动主题)的 functions.php 文件。已测试并有效。
要更改管理订单列表中显示的背景颜色,您将使用:
我正在使用以下代码为 Woocommerce 创建新的自定义订单状态。我遇到的问题是,在管理员中,状态显示为无样式。如何以类似于“正在处理”的方式设置自定义状态的样式?
/* Adding a new custom order status */
function register_manual_order_status() {
register_post_status( 'wc-manual', array(
'label' => 'Manual Order',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Manual order (%s)', 'Manual order (%s)' )
) );
}
add_action( 'init', 'register_manual_order_status' );
// Add to list of WC Order statuses
function add_manual_to_order_statuses( $order_statuses ) {
$new_order_statuses = array();
// add new order status after processing
foreach ( $order_statuses as $key => $status ) {
$new_order_statuses[ $key ] = $status;
if ( 'wc-processing' === $key ) {
$new_order_statuses['wc-manual'] = 'Manual';
}
}
return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_manual_to_order_statuses' );
不要使用 wc-manual
slug,因为 manual
slug 已在 WooCommerce 中保留并显示箭头。而是将您的状态标签更改为 wc-manual-order
,箭头将根据需要替换为状态名称。
因此您的代码将是:
// Add a custom order status
add_action( 'init', 'register_manual_order_status' );
function register_manual_order_status() {
register_post_status( 'wc-manual-order', array(
'label' => __('Manual Order'),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Manual order (%s)', 'Manual order (%s)' )
) );
}
// Add Custom order status after processing on order statuses dropdown
add_filter( 'wc_order_statuses', 'add_manual_to_order_statuses' );
function add_manual_to_order_statuses( $order_statuses ) {
$new_order_statuses = array();
foreach ( $order_statuses as $key => $status ) {
$new_order_statuses[ $key ] = $status;
if ( 'wc-processing' === $key ) {
$new_order_statuses['wc-manual-order'] = __('Manual');
}
}
return $new_order_statuses;
}
代码进入活动子主题(或活动主题)的 functions.php 文件。已测试并有效。
要更改管理订单列表中显示的背景颜色,您将使用: