Unfortunately WC_Order is no longer a post object. The ‘add_meta_boxes’ action (and the JSM Show Post Metadata callback) expects a post object (or an extended post object):
https://developer.wordpress.org/reference/hooks/add_meta_boxes/
js.
Actually you can still add meta boxes to the new order table, you just need to change the screen parameter. This is how I have done in my plugin:
// Register action in constructor or init method
add_action( 'add_meta_boxes', array( $this, 'meta_boxes' ) );
public function meta_boxes() {
// Add meta box to old orders screen (using posts table)
add_meta_box(
'my-plugin-id',
__( 'My Plugin Meta Box Title', 'my-plugin-namespace' ),
array( $this, 'meta_box_output' ),
'shop_order',
'side',
'high'
);
// Add meta box to new orders screen (using orders table)
add_meta_box(
'my-plugin-id',
__( 'My Plugin Meta Box Title', 'my-plugin-namespace' ),
array( $this, 'meta_box_output' ),
'woocommerce_page_wc-orders',
'side',
'high'
);
}
And in the meta_box_output function, I simply get the order like this:
public function meta_box_output( $order ) {
if ( get_class( $order ) === 'WP_Post' ) {
$order = wc_get_order( $order->ID );
}
// Do stuff with $order
}
@sarikk The issue is not adding a metabox to the order editing page – that’s not a problem – the issue is that orders are no longer WP_Post objects and WordPress meta data functions can no longer be used (WC order meta is now located in a different database table and has a different format).
I’ve written a new plugin to support WC order objects and metadata. It has been submitted to the wordpress.org plugin directory, but that may take a few weeks before it is approved. Meanwhile, you can find the plugin on GitHub at: https://github.com/jsmoriss/jsm-show-order-meta
js.