Wordpress 如何在woocommerce中创建自定义订单状态
我尝试了下面的代码来创建自定义状态Wordpress 如何在woocommerce中创建自定义订单状态,wordpress,woocommerce,Wordpress,Woocommerce,我尝试了下面的代码来创建自定义状态 add_action( 'init', function() { $term = get_term_by( 'name', 'shipped', 'shop_order_status' ); if ( ! $term ) { wp_insert_term( 'shipped', 'shop_order_status' ); } } ); 但它不起作用。我还尝试了其他一些方法。请任何人在此方面帮助我。您需要先注册自定义状
add_action( 'init', function() {
$term = get_term_by( 'name', 'shipped', 'shop_order_status' );
if ( ! $term ) {
wp_insert_term( 'shipped', 'shop_order_status' );
}
} );
但它不起作用。我还尝试了其他一些方法。请任何人在此方面帮助我。您需要先注册自定义状态,然后将其添加到订单状态数组中
function register_shipped_order_status() {
register_post_status( 'wc-shipped', array(
'label' => 'Shipped',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Shipped <span class="count">(%s)</span>', 'Shipped <span class="count">(%s)</span>' )
) );
}
add_action( 'init', 'register_shipped_order_status' );
add_filter( 'wc_order_statuses', 'custom_order_status');
function custom_order_status( $order_statuses ) {
$order_statuses['wc-shipped'] = _x( 'Shipped', 'Order status', 'woocommerce' );
return $order_statuses;
}
function register\u shipped\u order\u status(){
注册后状态('wc shipped',数组(
“标签”=>“已装运”,
“public”=>正确,
“从搜索中排除”=>false,
“在\u管理\u所有\u列表中显示\u”=>true,
“在管理状态列表中显示”=>true,
“label_count”=>\u n_noop('Shipped(%s)','Shipped(%s)')
) );
}
添加操作('init','register\u shipped\u order\u status');
添加过滤器(“wc订单状态”、“自定义订单状态”);
功能自定义订单状态($order\U status){
$order_status['wc-shipped']=_x('shipped','order status','woocommerce');
返回$order\u状态;
}
您需要先注册自定义状态,然后将其添加到订单状态数组中
function register_shipped_order_status() {
register_post_status( 'wc-shipped', array(
'label' => 'Shipped',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Shipped <span class="count">(%s)</span>', 'Shipped <span class="count">(%s)</span>' )
) );
}
add_action( 'init', 'register_shipped_order_status' );
add_filter( 'wc_order_statuses', 'custom_order_status');
function custom_order_status( $order_statuses ) {
$order_statuses['wc-shipped'] = _x( 'Shipped', 'Order status', 'woocommerce' );
return $order_statuses;
}
function register\u shipped\u order\u status(){
注册后状态('wc shipped',数组(
“标签”=>“已装运”,
“public”=>正确,
“从搜索中排除”=>false,
“在\u管理\u所有\u列表中显示\u”=>true,
“在管理状态列表中显示”=>true,
“label_count”=>\u n_noop('Shipped(%s)','Shipped(%s)')
) );
}
添加操作('init','register\u shipped\u order\u status');
添加过滤器(“wc订单状态”、“自定义订单状态”);
功能自定义订单状态($order\U status){
$order_status['wc-shipped']=_x('shipped','order status','woocommerce');
返回$order\u状态;
}