Get the value of wp_woocommerce_order_itemmeta metakey

WooCommerce Released
1 February, 2021 06:42:05
Orio
Topics: 1
Messages: 2
Hi there!

Is there a way to get the value of a specific metakey into the wp_woocommerce_order_itemmeta table if I'm using the Woocommerce order recordset? I would like to print this value inside a field of a template.

Thank you so much!

Orio
1 February, 2021 09:22:25
E2Pdf
Support
Topics: 7
Messages: 2592
Hi,

It looks like E2Pdf can't get this data directly at this moment, however we are working on update for "WooCommerce" extension and will take a look if we can include its support in nearest update, however can you let us know a bit more information so we can understand the task properly:

Are these data connected to some "shipping" order details? Or it's 3rd party plugin which add custom "item" type to orders? It will be very usefull if you will be able to attach maybe some screenshots how this information stored in "wp_woocommerce_order_itemmeta" table or let us know which 3rd party plugin is used. Thank you.

We remain at your service.
We would really appreciate your feedback at WordPress.org!
2 February, 2021 00:26:56
Orio
Topics: 1
Messages: 2
SOUNDS REALLY GREAT!!
In fact it wiil be so usefull to get directly values from wp_woocommerce_order_itemmeta. Many many many plugin use it to store data.

As you can see in the attached file, the table is very simple. Once u got the orderID you can easily filter directly by the name of the metakey, getting the value.

Please let me know how if I can hardcode this somewhere in the meanwhile you plan to insert this HUGE improvement in the next release!
2 February, 2021 03:21:02
E2Pdf
Support
Topics: 7
Messages: 2592
Hi,

If E2Pdf Template connected to "WooCommerce" extension and "Orders" item (screenshot 1), you can try to add custom filter to functions.php to change output of "e2pdf-wc-order" shortcode: https://codeshare.io/5eQRJb

The shortcode that must be used inside template: [e2pdf-wc-order key="custom_key" meta="true"] (screenshot 2)

It will require some modification to fit your needs however you must keep in mind that "wp_woocommerce_order_itemmeta" by default stores not the order data directly but items data which connected to order. Usually you can retrieve them by $order->get_items('shipping') for shipping, $order->get_items() for products, etc, that was the reason why we asked which information do you want to retrieve.

Let us know please if you will be able to adapt the code for your needs or you have any different settings.

We remain at your service.
We would really appreciate your feedback at WordPress.org!
2 February, 2021 04:38:29
E2Pdf
Support
Topics: 7
Messages: 2592
We also just released an RC version 1.13.29 which has built-in support of getting meta values.

You can apply update now by turning on updates from "e2pdf.com". Option can be enabled at "E2Pdf" -> "Settings" -> "Release Candidate Builds" (screenshot). After enabling this option you must be able check for updates at "Dashboard" -> "Updates" and update plugin as usual to version 1.13.29.

It's recommended to turn off this option after update

After update it will be possible to use such shortcodes:

[e2pdf-wc-order key="shipping" subkey="method_id" order_item_meta="true"] - to get custom item type meta data

By default it will iteration over all "shipping" items and will output array data. You can define "index" to get for example only first "shipping" item meta added to order or navigate via "path" attribute: https://e2pdf.com/support/desk/repeater-field-output

If you will need to get custom merged array output currently it's possible to do only via custom filter, where post_meta will be the array:

Filter to modify array_output: apply_filters('e2pdf_model_shortcode_e2pdf_wc_order_array', $post_meta, $atts)

---------------------------------------------------------

[e2pdf-wc-product key="wcpoa_order_attachment_order_arr" index="0" order_item_meta="true"] - to get product meta data, where "index" is index of product added to order.

Filter to modify array output: apply_filters('e2pdf_model_shortcode_e2pdf_wc_product_array', $post_meta, $atts)

Let us know please if you will have any issues or problems to accomplish the task.

We remain at your service.
We would really appreciate your feedback at WordPress.org!