在 Woocommerce 中添加多个自定义订单状态
Adding multiple custom order statuses in Woocommerce
我尝试了下面编写的这段代码,它成功了。唯一的问题是我需要再添加一个名为“Verification”的状态。如果你们能做到这一点,请帮助我。
function register_awaiting_shipment_order_status() {
register_post_status( 'wc-awaiting-shipment', array(
'label' => 'Awaiting shipment',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Awaiting shipment <span class="count">(%s)</span>', 'Awaiting shipment <span class="count">(%s)</span>' )
) );
}
add_action( 'init', 'register_awaiting_shipment_order_status' );
// Add to list of WC Order statuses
function add_awaiting_shipment_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-awaiting-shipment'] = 'Awaiting shipment';
}
}
return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_awaiting_shipment_to_order_statuses' );
以下代码将添加 "Awaiting shipment" 和 "Verification" 自定义订单状态,并将替换您问题的代码:
add_action( 'init', 'register_custom_statuses_as_order_status' );
function register_custom_statuses_as_order_status() {
register_post_status( 'wc-awaiting-shipment', array(
'label' => __('Awaiting shipment'),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Awaiting shipment <span class="count">(%s)</span>', 'Awaiting shipment <span class="count">(%s)</span>' )
) );
register_post_status( 'wc-verification', array(
'label' => __('Verification'),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Verification <span class="count">(%s)</span>', 'Verification <span class="count">(%s)</span>' )
) );
}
// Add to list of WC Order statuses
add_filter( 'wc_order_statuses', 'add_additional_custom_statuses_to_order_statuses' );
function add_additional_custom_statuses_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-awaiting-shipment'] = __('Awaiting shipment');
$new_order_statuses['wc-verification'] = __('Verification');
}
}
return $new_order_statuses;
}
代码进入您的活动子主题(活动主题)的 function.php 文件。已测试并有效。
我尝试了下面编写的这段代码,它成功了。唯一的问题是我需要再添加一个名为“Verification”的状态。如果你们能做到这一点,请帮助我。
function register_awaiting_shipment_order_status() {
register_post_status( 'wc-awaiting-shipment', array(
'label' => 'Awaiting shipment',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Awaiting shipment <span class="count">(%s)</span>', 'Awaiting shipment <span class="count">(%s)</span>' )
) );
}
add_action( 'init', 'register_awaiting_shipment_order_status' );
// Add to list of WC Order statuses
function add_awaiting_shipment_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-awaiting-shipment'] = 'Awaiting shipment';
}
}
return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_awaiting_shipment_to_order_statuses' );
以下代码将添加 "Awaiting shipment" 和 "Verification" 自定义订单状态,并将替换您问题的代码:
add_action( 'init', 'register_custom_statuses_as_order_status' );
function register_custom_statuses_as_order_status() {
register_post_status( 'wc-awaiting-shipment', array(
'label' => __('Awaiting shipment'),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Awaiting shipment <span class="count">(%s)</span>', 'Awaiting shipment <span class="count">(%s)</span>' )
) );
register_post_status( 'wc-verification', array(
'label' => __('Verification'),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Verification <span class="count">(%s)</span>', 'Verification <span class="count">(%s)</span>' )
) );
}
// Add to list of WC Order statuses
add_filter( 'wc_order_statuses', 'add_additional_custom_statuses_to_order_statuses' );
function add_additional_custom_statuses_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-awaiting-shipment'] = __('Awaiting shipment');
$new_order_statuses['wc-verification'] = __('Verification');
}
}
return $new_order_statuses;
}
代码进入您的活动子主题(活动主题)的 function.php 文件。已测试并有效。