Integrating with Woo High Performance Order Storage

In order to bring our Woo extensions up to speed and provide full compatibility with Woo we needed to make a few adjustments for the High Performance Order Storage (HPOS).  I’d like to briefly explain what HPOS is, the changes we noticed and how we adapted our own extensions to provide compatibility.

Understanding Woo HPOS

So, what exactly is Woo HPOS?  Previously termed “Custom Order Tables”, HPOS would restructure the database to move Woo order metadata out of the traditional wp_posts and wp_postmeta tables and into their own custom tables: _wc_orders, _wc_order_addresses, _wc_order_operational_data, and _wc_orders_meta.  Made available as an option that store owners can toggle on and off, HPOS required any Woo extensions to include some code to express compatibility with the new format, ensuring all elements of the store remain functional.  Essentially, the Create, Read, Update, Delete (CRUD) methods available on the WC_Order object would check this HPOS setting to know where to store the data in the database.  A full write-up of the change can be found here.

The Recipe for Success

Woo released a very helpful “recipe book” for developers to work through and bring their extensions up to speed.  This includes ensuring any order metadata was handled using the appropriate CRUD methods, console commands for reviewing your codebase for functionality that might not be using the correct methods, how to declare compatibility for HPOS within your extension and how to check whether HPOS was enabled within the current store.  This guide covered the vast majority of changes that we needed to make within our own extensions and they were relatively minor.

Beyond the cookbook

While testing the new features, there were a couple of nuances that we discovered, involving elements within the WordPress admin, that were altered when HPOS was enabled and required some additional attention:

  • Adding custom columns to the order listing screen (WooCommerce > Orders) and populating these columns with data:  Typically this is done using a core WordPress action and filter as Woo Orders are just a custom post type.  However, due to the data structure with HPOS enabled, this information is now pulled in from a different table, so this screen must be built differently.  Instead of using the default hooks: manage_edit-shop_order_columns, manage_shop_order_posts_custom_column, new hooks were introduced: woocommerce_shop_order_list_table_columns, woocommerce_shop_order_list_table_custom_column (shop_order being a dynamic element in all of these hooks indicating the post type we want to interact with).  The hooked methods work in exactly the same way but both versions of the hooks should be used to provide compatibility for all installs.
  • Adding custom order actions:  The woocommerce_order_actions filter hook had the WC_Order object added to it which should now be used to reference the current order instead of the $theorder global variable.

Overall, transitioning our extensions to support HPOS was a breeze, thanks to WooCommerce’s commitment to backward compatibility. By following the provided guidelines and addressing a few minor tweaks, we were able to ensure seamless integration and continued functionality for our users.


Leave a Reply

Your email address will not be published. Required fields are marked *