get_post_meta() gets data from db table wp_postmeta instead of wp_wc_orders_meta
-
Hello,
I use the following code to add the contents of some custom checkout fields to my invoices and packing slips:
function custom_order_info_fields( $fields, $order ) { $custom_fields = array( array( 'label' => 'Vergi Dairesi:', 'value' => get_post_meta( $order->get_id(), '_billing_vergidairesi', true ), ), array( 'label' => 'T.C./Vergi No:', 'value' => get_post_meta( $order->get_id(), '_billing_tckimlik_vergino', true ), ), ); $fields = array_merge( $fields, $custom_fields ); return $fields; } add_filter( 'wcdn_order_info_fields', 'custom_order_info_fields', 10, 2 );
The code works as intended except it gives empty values for the custom fields. There are no errors in debug logs, and when I dump some variables with:
var_dump(get_post_meta( $order->get_id(), '', false ));
I see the get_post_meta() returns data from my db table wp_postmeta instead of wp_wc_orders_meta where the custom fields are stored. wp_postmeta does have entries for every orderID that has a successful payment, because my payment gateway plugin stores them there, I’m not sure how or why.
Why does this happen and how do I make get_post_meta() return custom checkout fields?
Everything else seems to work fine. Below is my related config:
- WordPress 6.4.3
- WooCommerce 8.5.2
- Checkout Field Editor for WooCommerce 2.0.0
- Raft 1.1.1 (theme)
- Code Snippets 3.6.2
- Print Invoice & Delivery Notes for WooCommerce 4.8.1
The page I need help with: [log in to see the link]
- The topic ‘get_post_meta() gets data from db table wp_postmeta instead of wp_wc_orders_meta’ is closed to new replies.