[HPOS] Implement "Empty Trash" functionality in list table (#35489)
This commit is contained in:
parent
736593ef15
commit
bddb65699b
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: add
|
||||
|
||||
Add "Empty Trash" functionality to HPOS list table.
|
|
@ -2589,6 +2589,10 @@ ul.wc_coupon_list_block {
|
|||
height: 30px;
|
||||
}
|
||||
}
|
||||
|
||||
#order-query-submit {
|
||||
margin: 0 8px 0 0;
|
||||
}
|
||||
}
|
||||
|
||||
.wp-list-table {
|
||||
|
|
|
@ -33,6 +33,13 @@ class ListTable extends WP_List_Table {
|
|||
*/
|
||||
private $page_controller;
|
||||
|
||||
/**
|
||||
* Tracks whether we're currently inside the trash.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $is_trash = false;
|
||||
|
||||
/**
|
||||
* Sets up the admin list table for orders (specifically, for orders managed by the OrdersTableDataStore).
|
||||
*
|
||||
|
@ -281,6 +288,9 @@ class ListTable extends WP_List_Table {
|
|||
'total_pages' => $max_num_pages,
|
||||
)
|
||||
);
|
||||
|
||||
// Are we inside the trash?
|
||||
$this->is_trash = isset( $_REQUEST['status'] ) && 'trash' === $_REQUEST['status'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -458,7 +468,7 @@ class ListTable extends WP_List_Table {
|
|||
submit_button( __( 'Filter', 'woocommerce' ), '', 'filter_action', false, array( 'id' => 'order-query-submit' ) );
|
||||
}
|
||||
|
||||
if ( $this->is_trash && $this->has_items() && current_user_can( 'edit_others_orders' ) ) {
|
||||
if ( $this->is_trash && $this->has_items() && current_user_can( 'edit_others_shop_orders' ) ) {
|
||||
submit_button( __( 'Empty Trash', 'woocommerce' ), 'apply', 'delete_all', false );
|
||||
}
|
||||
|
||||
|
@ -886,6 +896,19 @@ class ListTable extends WP_List_Table {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current action selected from the bulk actions dropdown.
|
||||
*
|
||||
* @return string|false The action name. False if no action was selected.
|
||||
*/
|
||||
public function current_action() {
|
||||
if ( ! empty( $_REQUEST['delete_all'] ) ) {
|
||||
return 'delete_all';
|
||||
}
|
||||
|
||||
return parent::current_action();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle bulk actions.
|
||||
*/
|
||||
|
@ -901,6 +924,22 @@ class ListTable extends WP_List_Table {
|
|||
$redirect_to = remove_query_arg( array( 'deleted', 'ids' ), wp_get_referer() );
|
||||
$redirect_to = add_query_arg( 'paged', $this->get_pagenum(), $redirect_to );
|
||||
|
||||
if ( 'delete_all' === $action ) {
|
||||
// Get all trashed orders.
|
||||
$ids = wc_get_orders(
|
||||
array(
|
||||
'type' => 'shop_order',
|
||||
'status' => 'trash',
|
||||
'limit' => -1,
|
||||
'return' => 'ids',
|
||||
)
|
||||
);
|
||||
|
||||
$action = 'delete';
|
||||
} else {
|
||||
$ids = isset( $_REQUEST['order'] ) ? array_reverse( array_map( 'absint', $_REQUEST['order'] ) ) : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows 3rd parties to modify order IDs about to be affected by a bulk action.
|
||||
*
|
||||
|
@ -908,7 +947,7 @@ class ListTable extends WP_List_Table {
|
|||
*/
|
||||
$ids = apply_filters( // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingSinceComment
|
||||
'woocommerce_bulk_action_ids',
|
||||
isset( $_REQUEST['order'] ) ? array_reverse( array_map( 'absint', $_REQUEST['order'] ) ) : array(),
|
||||
$ids,
|
||||
$action,
|
||||
'order'
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue