WooCommerce: View Product/Order Hidden Custom Fields (“Protected Meta”)

I was working on a WooCommerce project recently and I didn’t want to waste time searching through all the hidden product post meta.

Post meta are basically product custom fields that are added via the update_post_meta() WordPress function by WooCommerce itself, a custom plugin, a snippet, a theme. For example, “total_sales” is a default WooCommerce product custom field that updates every time the product is purchased. You can “get” total sales with the get_post_meta() WordPress function.

In the same way, there are dozens of default and third party product custom fields that are stored inside the WooCommerce product meta. If the product custom field “meta key” starts with an underscore (“_”), however, this won’t be visible in the “Custom Fields” section of the edit product page screen. Which is a bummer.

So, today, I’ll show you a quick trick so you can always know what the values for product meta keys are without having to mess with print_r() or error_log() in your PHP functions. In the image below, you see the final outcome.

Please note this also shows order hidden meta.

Enjoy!

WordPress will not show custom fields which have meta_key starting with an “_” (underscore) in the custom fields list on the post edit screen. Here on the single product page edit screen, after installing my snippet, you can now see how “_backorders” is now visible for example. That was previously hidden!

PHP Snippet: Show Post/Product/Order/Page Hidden Custom Fields @ Edit Post Page

/**
 * @snippet       Show Hidden Custom Fields @ WooCommerce Product / Order Edit
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 5.1
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_filter( 'is_protected_meta', '__return_false' ); 
Was this article helpful?
YesNo

Where to add custom code?

You should place PHP snippets at the bottom of your child theme functions.php file and CSS at the bottom of its style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my guide "Should I Add Custom Code Via WP Editor, FTP or Code Snippets?" and my video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything went as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting.

If you think this code saved you time & money, feel free to join 17,000+ WooCommerce Weekly subscribers for blog post updates and 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance!

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

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.

14 thoughts on “WooCommerce: View Product/Order Hidden Custom Fields (“Protected Meta”)

  1. Doesn’t work

    1. Maybe your “custom fields” section is hidden? If yes, try clicking on the top right “Screen options” and check custom fields. Let me know

  2. I added the snippet at the bottom of child theme functions.php and no meta fields appear at the product backend page.

    1. This still works for sure as I use it on client sites. Sure you have the custom fields meta box visible on that page?

  3. Gosh, this saved me a ton of time in troubleshooting some issues with funky subscriptions. Added the snippet to my site today using the Code Snippets plugin from the WP repo. Was able to view custom fields added to a subscription order and the related renewal orders. Using WooCommerce 6.0.0 on WordPress 5.8.3. Excellent work Rodolfo. I think I’ll just drop this little tweak into my site’s functionality plugin.

  4. Works fine and added it today 7 August 2021

  5. Hello, how to completely remove these fields from Woocommerce orders? We have e.g. mailchimp_woocommerce_landing_site and 30+ other theme fields. Best!

    1. Hi Seba, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  6. Hi Rodolfo

    Thanks for the tip — very useful. Is there any way to see the meta keys/values that have been added to product variations?

    Thanks

    tom

    1. Hello Tom, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  7. Hi Rodolfo!
    thank you for your useful information. You are right – there are a dozen of hidden or visible custom/meta fields in every product and order. I found even very old meta I created long-long time ago for products I do not have right now.
    Is there any reason to keep these in site’s DB or to wipe them for DB speed reason?

    1. Great! No, I don’t think this slows down the DB by a lot, unless you have 100,000 products

Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. 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 BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)

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