woocommerce 新增一个订单状态

原来woocommerce 内置的订单状态就有 待付款、正在处理、保留、已完成、已取消、已退款、失败订单,但是在实际使用中,我们会发现这些状态不够用,比如说我想有一个状态称为 待发货,就可以使用下面的两个方法和woocommerce提供的api来实现。

 

/**  
 * Register new status 
 **/ 
 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' ); 

 

参考链接

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值