WPIntell

Source evidence

woocommerce meta data

JSM Show Post Metadata · support · 2023-11-10T07:36:00+00:00

mixedsentiment
mediumseverity
0.84relevance
3replies
Evidence linked to opportunitycommercial context

Proof Health

Open evidence

Commercial opportunities need traceable source links before they are treated as build-worthy.

5 / 34 rows with source links

14.7% of this page's analysis has direct source links.

0 build-decision rows missing links

0 rows here require auditable proof before promotion.

29 rows with no attached evidence

0 rows have source counts but still need direct links.

Conversation

support
uswine resolved
Woocommerce just did a major database update on orders… your plugin no longer works on the woocommerce orders page 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.

Comments

3 shown
JS Morisset 2023-11-10T18:48:00+00:00

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.

sarikk 2024-01-02T07:11:00+00:00

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 }

JS Morisset 2024-01-24T00:18:00+00:00

@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.