wordpress - 在 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
推荐阅读
- c# - 使用流进行图像解码的列表视图
- javascript - 摇动以撤消问题 ios Safari
- java - '蜂巢上的火花' - 引起:java.lang.ClassNotFoundException:org.apache.hive.spark.counter.SparkCounters
- r - ggplot 将不同的图形合二为一
- javascript - 在根和任何对象之间的对象树中查找对象
- neo4j - 如何检查节点是否全局存在并在 Cypher 中设置条件?
- storage - 存储 api 不适用于 Microsoft Edge 上的自签名扩展
- sql-server - SQL Server 命名实例 TCPIP 端口设置和端点/基础结构权限错误
- python-3.x - 当我多次运行此代码片段时,它会在 python 中生成一个随机偶数,它会打印“无”一段时间。为什么会这样?
- java - Windows 上的 Java 时钟精度:15-16ms