Skip to content

Conversation

@barryhughes
Copy link
Member

@barryhughes barryhughes commented Oct 31, 2022

Adds filter hook handle_bulk_actions-woocommerce_page_wc-orders to the HPOS admin list table.

This is a duplicate of core WP hook handle_bulk_actions-<SCREEN_ID> and allows for custom bulk actions to be handled in the context of the admin list table for HPOS orders.

Closes #35414.

All Submissions:

How to test the changes in this Pull Request:

First, in case handy, here is a quick reminder on how to enable HPOS, etc 💡

  • If necessary, start by running the WooCommerce ▸ Status ▸ Tools ▸ Create Custom Order Tables tool.
  • Then, visit WooCommerce ▸ Settings ▸ Advanced ▸ Features and enable High-Performance Order Storage.
  • Next, head on over to WooCommerce ▸ Settings ▸ Advanced ▸ Custom Data Stores and:
    • Select Use the WordPress posts table.
    • Select Keep the posts table and the orders tables synchronized.
  1. Start by adding the following snippet to a suitable location, such as a wp-content/mu-plugin file (the goal of this snippet is to simulate how a 3PD might add a custom bulk action for orders):
$add_custom_bulk_action = function ( array $bulk_actions ) {
	return array_merge( $bulk_actions, [ 'custom-bulk-action' => 'Perform Custom Action!' ] );
};

$custom_bulk_action_handler = function ( string $redirect_to, string $action, array $ids ) {
	return $action === 'custom-bulk-action'
		? add_query_arg( 'bulk_action', 'custom-bulk-action-notice', $redirect_to )
		: $redirect_to;
};

$custom_bulk_action_notice = function () {
	if ( isset( $_GET['bulk_action'] ) && 'custom-bulk-action-notice' === $_GET['bulk_action'] ) {
		print '<div class="updated" style="border-left-color: #d7f"><p>Custom Bulk Action Handler Fired</p></div>';
	}
};

add_filter( 'bulk_actions-woocommerce_page_wc-orders', $add_custom_bulk_action );
add_filter( 'handle_bulk_actions-woocommerce_page_wc-orders', $custom_bulk_action_handler, 10, 3 );
add_action( 'admin_notices', $custom_bulk_action_notice );
  1. With HPOS enabled (and WooCommerce Orders Tables set as the authoritative data store for orders), visit the order list screen. You should see a new bulk action ("Perform Custom Action!"):

hpos-custom-bulk-action

  1. Check the boxes for one or more order rows, select the above bulk action, and click on the "Apply" button. Once the page finishes reloading, you should see an admin notice like the following one:

hpos-custom-bulk-action-notice

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable? No, we generally don't add tests when we add new hooks in isolation (within WooCommerce, nothing functional is actually changing).
  • Have you created a changelog file for each project being changed, ie pnpm --filter=<project> changelog add?

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

…he HPOS admin list table.

This is a duplicate of core WP hook `handle_bulk_actions-<SCREEN_ID>` and allows for custom bulk actions to be handled in the context of the admin list table for HPOS orders.
@github-actions github-actions bot added focus: react admin plugin: woocommerce Issues related to the WooCommerce Core plugin. labels Oct 31, 2022
@barryhughes barryhughes requested review from a team and jorgeatorres and removed request for a team October 31, 2022 22:42
@github-actions
Copy link
Contributor

Test Results Summary

Commit SHA: 35100e0

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests24800302511m 10s
E2E Tests186006019220m 2s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

Copy link
Member

@jorgeatorres jorgeatorres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🥇. Thanks @barryhughes!

@jorgeatorres jorgeatorres merged commit 2fcb28b into trunk Nov 1, 2022
@jorgeatorres jorgeatorres deleted the fix/35414-custom-bulk-actions branch November 1, 2022 22:36
@github-actions github-actions bot added this to the 7.2.0 milestone Nov 1, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Nov 1, 2022

Hi @jorgeatorres, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:

  • Add the release: add testing instructions label

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[HPOS] Add action for handling custom bulk actions.

3 participants