get_post_meta not worked
-
I am currently working on a WooCommerce project and encountering an issue with retrieving a specific meta key value for orders. I have a function (Myplugin_admin_order_details) hooked to the woocommerce_admin_order_data_after_order_details action, and I’m attempting to retrieve the value of the _stripe_currency meta key for a given order.
Here is the relevant code snippet:
add_action( ‘woocommerce_admin_order_data_after_order_details’, ‘Myplugin_admin_order_details’, 10, 3 );
function Myplugin_admin_order_details( $order ) {
$order_id = $order->get_id();echo "<pre>"; // This line prints all meta data, including 'my_custom_key' print_r( $order->get_meta_data() ); // However, this line does not return any value for 'my_custom_key' echo get_post_meta( $order_id, "my_custom_key", true );
}
While $order->get_meta_data() correctly displays all meta data, the get_post_meta function does not return any value for the my_custom_key meta key, even though I am certain that the key exists for the order.
why this might be happening and how I can successfully retrieve the value of the my_custom_key meta key.
- The topic ‘get_post_meta not worked’ is closed to new replies.