Nếu bạn muốn thêm trạng thái đơn hàng mới trong WooCommerce ví dụ như “Đang giao hàng”, bài viết này sẽ giúp bạn.
Mình ví dụ thêm trạng thái Đang giao hàng, tại functions.php
.
/**
* Thêm trạng thái đơn hàng
*/
function register_on_delivery_order_status() {
register_post_status( 'wc-on-delivery', array(
'label' => 'Đang giao hàng',
'public' => true,
'show_in_admin_status_list' => true,
'show_in_admin_all_list' => true,
'exclude_from_search' => false,
'label_count' => _n_noop( 'Đang giao hàng <span class="count">(%s)</span>', 'Đang giao hàng <span class="count">(%s)</span>' )
) );
}
add_action( 'init', 'register_on_delivery_order_status' );
function add_on_delivery_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-on-delivery'] = 'Đang giao hàng';
}
}
return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_on_delivery_to_order_statuses' );
Để trạng thái Đang giao hàng có màu sắc riêng biệt, các bạn thêm đoạn mã sau.
<?php
function woo_order_status_admin_css() { ?>
<style type="text/css" media="screen">
.order-status.status-on-delivery {
background: #d8eafc;
color: #1e87f0;
}
</style> <?php
}
add_action('admin_head', 'woo_order_status_admin_css');
Chúc các bạn thành công!
Không có bình luận.