Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save woogists/fba058890c3a49f649fc6fe8eb9ddf7c to your computer and use it in GitHub Desktop.
Save woogists/fba058890c3a49f649fc6fe8eb9ddf7c to your computer and use it in GitHub Desktop.
[Customizing checkout fields using actions and filters] Display WooCommerce custom checkout field admin order page.
/**
* Display field value on the order edit page
*/
add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order){
echo '<p><strong>'.__('My Field').':</strong> ' . get_post_meta( $order->id, 'My Field', true ) . '</p>';
}
@8ozStudios
Copy link

FYI, line 7 throws an error in the admin section. $order->id should be $order->get_id().

Source: https://stackoverflow.com/questions/43231684/order-properties-should-not-be-accessed-directly-woocommerce-3-0

@kshitiz621
Copy link

How do I display the same input data to customer order details page on my accounts page?

@LineaDe
Copy link

LineaDe commented May 26, 2021

FYI, line 7 throws an error in the admin section. $order->id should be $order->get_id().

Source: https://stackoverflow.com/questions/43231684/order-properties-should-not-be-accessed-directly-woocommerce-3-0

Yes that is the case, full error message is: "Notice: id was called incorrectly. Order properties should not be accessed directly. Backtrace: require('wp-admin/edit-form-advanced.php'), do_meta_boxes, WC_Meta_Box_Order_Data::output, do_action('woocommerce_admin_order_data_after_billing_address'), WP_Hook->do_action, WP_Hook->apply_filters, wpdesk_vat_number_display_admin_order_meta, WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong Please see Debugging in Website for more information. (This message was added in version 3.0.) in ****/wp-includes/functions.php on line 5313"

Found a nice solution here https://stackoverflow.com/questions/65359251/display-custom-meta-data-in-woocommerce-admin-order-after-billing-address

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment