Добавление нескольких пользовательских статусов заказов в Woocommerce

Я попробовал этот код, написанный ниже, и он работал. Единственная проблема заключается в том, что мне нужен еще один статус, который называется «Проверка». Пожалуйста, помогите мне, если это то, что вы, ребята, можете сделать.

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' );

1

Решение

Следующий код, добавит «Ожидание Доставки» а также «Проверка» пользовательские статусы заказа и он заменит код из вашего вопроса:

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 вашей активной дочерней темы (active theme). Проверено и работает.

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector