Automattic\WooCommerce\Internal\Admin\Orders

ListTable::handle_bulk_actions()publicWC 1.0

Handle bulk actions.

Method of the class: ListTable{}

Return

null. Nothing (null).

Usage

$ListTable = new ListTable();
$ListTable->handle_bulk_actions();

ListTable::handle_bulk_actions() code WC 8.6.1

public function handle_bulk_actions() {
	$action = $this->current_action();

	if ( ! $action ) {
		return;
	}

	check_admin_referer( 'bulk-orders' );

	$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'   => $this->order_type,
				'status' => 'trash',
				'limit'  => -1,
				'return' => 'ids',
			)
		);

		$action = 'delete';
	} else {
		$ids = isset( $_REQUEST['id'] ) ? array_reverse( array_map( 'absint', (array) $_REQUEST['id'] ) ) : array();
	}

	/**
	 * Allows 3rd parties to modify order IDs about to be affected by a bulk action.
	 *
	 * @param array Array of order IDs.
	 */
	$ids = apply_filters( // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingSinceComment
		'woocommerce_bulk_action_ids',
		$ids,
		$action,
		'order'
	);

	if ( ! $ids ) {
		wp_safe_redirect( $redirect_to );
		exit;
	}

	$report_action  = '';
	$changed        = 0;
	$action_handled = true;

	if ( 'remove_personal_data' === $action ) {
		$report_action = 'removed_personal_data';
		$changed       = $this->do_bulk_action_remove_personal_data( $ids );
	} elseif ( 'trash' === $action ) {
		$changed       = $this->do_delete( $ids );
		$report_action = 'trashed';
	} elseif ( 'delete' === $action ) {
		$changed       = $this->do_delete( $ids, true );
		$report_action = 'deleted';
	} elseif ( 'untrash' === $action ) {
		$changed       = $this->do_untrash( $ids );
		$report_action = 'untrashed';
	} elseif ( false !== strpos( $action, 'mark_' ) ) {
		$order_statuses = wc_get_order_statuses();
		$new_status     = substr( $action, 5 );
		$report_action  = 'marked_' . $new_status;

		if ( isset( $order_statuses[ 'wc-' . $new_status ] ) ) {
			$changed = $this->do_bulk_action_mark_orders( $ids, $new_status );
		} else {
			$action_handled = false;
		}
	} else {
		$action_handled = false;
	}

	// Custom action.
	if ( ! $action_handled ) {
		$screen = get_current_screen()->id;

		/**
		 * This action is documented in /wp-admin/edit.php (it is a core WordPress hook).
		 *
		 * @since 7.2.0
		 *
		 * @param string $redirect_to The URL to redirect to after processing the bulk actions.
		 * @param string $action      The current bulk action.
		 * @param int[]  $ids         IDs for the orders to be processed.
		 */
		$custom_sendback = apply_filters( "handle_bulk_actions-{$screen}", $redirect_to, $action, $ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
	}

	if ( ! empty( $custom_sendback ) ) {
		$redirect_to = $custom_sendback;
	} elseif ( $changed ) {
		$redirect_to = add_query_arg(
			array(
				'bulk_action' => $report_action,
				'changed'     => $changed,
				'ids'         => implode( ',', $ids ),
			),
			$redirect_to
		);
	}

	wp_safe_redirect( $redirect_to );
	exit;
}