Automattic\WooCommerce\Internal\StockNotifications\Admin

ListTable::process_bulk_actionprivateWC 1.0

Process bulk actions.

Method of the class: ListTable{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->process_bulk_action();

ListTable::process_bulk_action() code WC 10.3.6

private function process_bulk_action() {
	if ( ! $this->current_action() ) {
		return;
	}

	check_admin_referer( 'bulk-' . $this->_args['plural'] );

	$notifications = isset( $_GET['notification'] ) && is_array( $_GET['notification'] ) ? array_map( 'absint', $_GET['notification'] ) : array();

	if ( empty( $notifications ) ) {
		return;
	}

	$redirect_url = NotificationsPage::PAGE_URL;

	if ( 'enable' === $this->current_action() ) {
		foreach ( $notifications as $id ) {

			$notification = Factory::get_notification( $id );
			$notification->set_status( NotificationStatus::ACTIVE );
			$this->data_store->update( $notification );

		}
		$notice_message = sprintf(
			/* translators: %s: Notifications count */
			_nx(
				'%s notification updated.',
				'%s notifications updated.',
				count( $notifications ),
				'notifications_status',
				'woocommerce'
			),
			count( $notifications )
		);

		NotificationsPage::add_notice( $notice_message, 'success' );

	} elseif ( 'cancel' === $this->current_action() ) {
		foreach ( $notifications as $id ) {
			$notification = Factory::get_notification( $id );
			$notification->set_status( NotificationStatus::CANCELLED );
			$this->data_store->update( $notification );
		}

		$notice_message = sprintf(
			/* translators: %s: Notifications count */
			_nx(
				'%s notification updated.',
				'%s notifications updated.',
				count( $notifications ),
				'notifications_status',
				'woocommerce'
			),
			count( $notifications )
		);

		NotificationsPage::add_notice( $notice_message, 'success' );

	} elseif ( 'delete' === $this->current_action() ) {
		foreach ( $notifications as $id ) {
			$notification = Factory::get_notification( $id );
			$this->data_store->delete( $notification );
		}

		$notice_message = sprintf(
			/* translators: %s: Notifications count */
			_nx(
				'%s notification deleted.',
				'%s notifications deleted.',
				count( $notifications ),
				'notifications_status',
				'woocommerce'
			),
			count( $notifications )
		);

		NotificationsPage::add_notice( $notice_message, 'success' );
	}

	wp_safe_redirect( $redirect_url );
	exit();
}