在WooCommerce管理员订单列表中以批量操作添加自定义取消订单状态

阿迪尔·阿里|

我想取消WooCommerce管理员订单列表中的所有选定订单。

我已经编写了代码,但是没有用

add_filter( 'bulk_actions-edit-shop_order', 'my_register_bulk_action' ); // edit-shop_order is the screen ID of the orders page

function my_register_bulk_action( $bulk_actions ) {

$bulk_actions['mark_change_status_to_cancelled'] = 'Order Cancel'; // <option value="mark_awaiting_shipment">Order Cancel</option>
return $bulk_actions;


}



/*
 * Bulk action handler
 * Make sure that "action name" in the hook is the same like the option value from the above function
 */
add_action( 'admin_action_mark_change_status_to_cancelled', 'my_bulk_process_custom_status' ); // admin_action_{action name}

function my_bulk_process_custom_status() {


// if an array with order IDs is not presented, exit the function
if( !isset( $_REQUEST['post'] ) && !is_array( $_REQUEST['post'] ) )
    return;

foreach( $_REQUEST['post'] as $order_id ) {

    $order = new WC_Order( $order_id );
    $order_note = 'That\'s what happened by bulk edit:';
    $order->update_status( 'Cancelled', $order_note, true ); // "my-shipment" is the order status name 
}

// of course using add_query_arg() is not required, you can build your URL inline
$location = add_query_arg( array(
        'post_type' => 'shop_order',
    'mark_change_status_to_cancelled' => 1, // mark_change_status_to_cancelled=1 is just the $_GET variable for notices
    'changed' => count( $_REQUEST['post'] ), // number of changed orders
    'ids' => join( $_REQUEST['post'], ',' ),
    'post_status' => 'all'
), 'edit.php' );

wp_redirect( admin_url( $location ) );
exit;


}

/*
 * Notices
 */
add_action('admin_notices', 'my_custom_order_status_notices');


function my_custom_order_status_notices() {

    global $pagenow, $typenow;


if( $typenow == 'shop_order' 
 && $pagenow == 'edit.php'
 && isset( $_REQUEST['mark_change_status_to_cancelled'] )
 && $_REQUEST['mark_change_status_to_cancelled'] == 1
 && isset( $_REQUEST['changed'] ) ) {

    $message = sprintf( _n( 'Order status changed.', '%s order statuses changed.', $_REQUEST['changed'] ), number_format_i18n( $_REQUEST['changed'] ) );
    echo "<div class=\"updated\"><p>{$message}</p></div>";

}


}

http://prntscr.com/oba9vg

现在,它在批量操作下显示了“取消订单”,但是不幸的是,该功能并未取消订单。我该怎么办?

时间

对于本节:

foreach( $_REQUEST['post'] as $order_id ) {

    $order = new WC_Order( $order_id );
    $order_note = 'That\'s what happened by bulk edit:';
    $order->update_status( 'Cancelled', $order_note, true ); // "my-shipment" is the order status name 
}

请使用"cancelled"代替"Cancelled"

$order->update_status( 'cancelled', $order_note, true );

我认为,这样就可以了。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在Woocommerce管理员订单列表上处理多个自定义批量操作

仅在WooCommerce管理员订单列表自定义列中显示特定订单状态的数据

Woocommerce 3.3管理员订单列表中的自定义订单状态背景按钮颜色

在Woocommerce管理员订单列表“订单”现有列中添加自定义字段

将自定义订单状态添加到WooCommerce管理员订单列表中的过滤器菜单

WooCommerce 管理订单列表中自定义订单状态的操作按钮问题

在Woocommerce管理员订单列表自定义列中显示结帐字段值

在Woocommerce管理员订单列表自定义列中显示用户名

在Woocommerce中处理管理订单列表上的自定义批量操作

在Woocommerce 3中将自定义批量操作添加到管理订单列表

将img添加到Woocommerce的管理订单列表中的自定义操作按钮

在WooCommerce管理订单列表中添加自定义操作按钮

通过WooCommerce管理员批量订单操作获取自定义计算

在Woocommerce管理订单列表中显示具有“全部”自定义状态的订单

在Woocommerce管理员订单编辑页面中以编程方式添加自定义订单注释

单击以在WooCommerce管理订单列表中显示文本时隐藏自定义操作按钮

在Woocommerce管理订单列表中添加可排序的自定义列

自定义操作按钮进入WooCommerce管理订单列表上的自定义列

在 WooCommerce 我的帐户订单列表中添加发送给客户的管理员订单备注

在Woocommerce管理员订单列表中显示带有作者和日期的订单注释

在WooCommerce管理员订单列表中显示每个订单的变体名称

如何在管理员上编辑或自定义WooCommerce添加订单按钮

如何为WooCommerce订单页面(管理员)添加自定义字段?

WooCommerce 自定义订单状态并添加此状态批量操作下拉

在 WooCommerce 管理订单列表的自定义列中显示私人和客户管理注释

将自定义ajax按钮添加到WooCommerce管理订单列表

在WooCommerce中将自定义URL链接添加到管理订单列表页面

在Woocommerce管理员,订单和电子邮件中显示自定义付款字段

在WooCommerce管理员快速订单预览中自定义内容