WooCommerce: Add Custom Meta Box @ Order Admin

When you edit an order as an admin, you’re presented with the usual WooCommerce layout: order details on the left, order action on the right, the list of order items on the bottom left, and – possibly – additional meta boxes added by third party plugins (e.g. the PDF Invoice and Packing List plugin order meta box where you can define the invoice date and number).

On top of that, it’s also possible, of course, to define our own custom meta boxes, so that the administrator and/or shop managers can view (or even enter) additional information.

I’ve used it on a client website to show a custom field, but you can print anything you wish – even documentation for shop managers (how to complete the order for example).

So, here’s how we add a new “section” (meta box) to the single order edit page in the WordPress dashboard, and how we display some content in it. Enjoy!

Here’s a brand new single order meta box called “Custom Box”. You can use it to print any HTML content or even use $post to access the current order post and get a custom field.

PHP Snippet: Custom Meta Box @ WooCommerce Edit Order Page

/**
 * @snippet       Add Meta Box @ WooCommerce Edit Order
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 7
 * @community     https://businessbloomer.com/club/
 */

add_action( 'add_meta_boxes', 'bbloomer_order_meta_box' );

function bbloomer_order_meta_box() {
    add_meta_box( 'custom_box', 'Custom Box', 'bbloomer_single_order_meta_box', 'shop_order', 'advanced', 'high' );
}

function bbloomer_single_order_meta_box() {
    // global $post; // OPTIONALLY USE TO ACCESS ORDER POST
    echo 'Whatever HTML content';
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

11 thoughts on “WooCommerce: Add Custom Meta Box @ Order Admin

  1. This snippet not working…

    1. Works for me! What error do you get?

      1. Nothing error.
        just no new block is created…

        1. Tried it again, it still works. Must be something else

          1. i tried, but again not work…

            1. Maybe your theme (or another plugin) is messing/conflicting with my snippet.

              To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentytwenty” theme (load the snippet there in functions.php) as explained here: https://www.businessbloomer.com/lesson/trwm4l01/

              Once you do that, does it work? If yes, you have a problem with your current theme or one of the plugins.

              Hope this helps!

              1. all problem is from HPOS, when woocommerce is in HPOS, then replace screen from function: ‘shop_order’ with ‘woocommerce_page_wc-orders’

                1. Interesting, thank you – didn’t know that!

  2. This was working for a long time , after an update when i clicked the button this didnt work.It’s not even loading the page ,i mean the button doing nothing.Can you help please?

    1. Which button, Dimos?

      1. Dimos probably set woocommerce to HPOS , and it doesnt work with that

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *