在 WooCommerce 中使用自定义订单状态时允许订单完全可编辑
Allow order to be fully editable while using a custom order status in WooCommerce
我在使用自定义状态时在订单中编辑数量时遇到错误。编辑箭头好像不见了?
我可以在注册自定义订单状态时包含其他值吗?
这是我的代码:
// Register new status 'To order'
function register_new_on_hold_order_status2() {
register_post_status( 'wc-to-order', array(
'label' => 'To order',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'To order (%s)', 'To order (%s)' )
) );
}
add_action( 'init', 'register_new_on_hold_order_status2' );
// Add to list of WC Order statuses
function add_on_hold_new_to_order_statuses2( $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 ) { // Here we Define after which to be added
$new_order_statuses['wc-to-order'] = 'To order';
}
}
return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_on_hold_new_to_order_statuses2' );
这不是错误,某些订单状态(例如 processing
不允许编辑订单。要更改此设置,您可以使用 wc_order_is_editable
挂钩
所以你得到:
function filter_wc_order_is_editable( $editable, $order ) {
// Compare
if ( $order->get_status() == 'your-status' ) {
$editable = true;
}
return $editable;
}
add_filter( 'wc_order_is_editable', 'filter_wc_order_is_editable', 10, 2 );
注:使用woocommerce_register_shop_order_post_statuses
与 init
相反,同时注册自定义订单状态,如
第二部分中所应用
我在使用自定义状态时在订单中编辑数量时遇到错误。编辑箭头好像不见了?
我可以在注册自定义订单状态时包含其他值吗?
这是我的代码:
// Register new status 'To order'
function register_new_on_hold_order_status2() {
register_post_status( 'wc-to-order', array(
'label' => 'To order',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'To order (%s)', 'To order (%s)' )
) );
}
add_action( 'init', 'register_new_on_hold_order_status2' );
// Add to list of WC Order statuses
function add_on_hold_new_to_order_statuses2( $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 ) { // Here we Define after which to be added
$new_order_statuses['wc-to-order'] = 'To order';
}
}
return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_on_hold_new_to_order_statuses2' );
这不是错误,某些订单状态(例如 processing
不允许编辑订单。要更改此设置,您可以使用 wc_order_is_editable
挂钩
所以你得到:
function filter_wc_order_is_editable( $editable, $order ) {
// Compare
if ( $order->get_status() == 'your-status' ) {
$editable = true;
}
return $editable;
}
add_filter( 'wc_order_is_editable', 'filter_wc_order_is_editable', 10, 2 );
注:使用woocommerce_register_shop_order_post_statuses
与 init
相反,同时注册自定义订单状态,如