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
 * @community     https://businessbloomer.com/club/
 */

add_filter( 'is_protected_meta', '__return_false' ); 

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

  • WooCommerce: Add Custom Field to Product Variations
    Adding and displaying custom fields on WooCommerce products is quite simple. For example, you can add a “RRP/MSRP” field to a product, or maybe use ACF and display its value on the single product page. Easy, yes. Unfortunately, the above only applies to “simple” products without variations (or the parent product if it’s a variable […]
  • WooCommerce: Get Product Data (ID, SKU, $) From $product Object
    I’ve been wanting to publish this guide for a long while. As a WooCommerce development freelancer, every day I repeat many operations that make me waste time… and one of them is indeed “How to get ____ if I have the $product variable/object?“. For example, “How can I get the product SKU“? Or “How can […]
  • WooCommerce: Add Custom Product Fields (e.g. RRP) Without a Plugin
    The manufacturer’s suggested retail price (MSRP), or the recommended retail price (RRP), is the price at which the manufacturer recommends that the retailer sells the product at. You might have seen this in an ad, on a magazine, on a price tag: “RRP: $50. Our price: $39!”. WooCommerce entrepreneurs can take advantage of this “marketing […]
  • WooCommerce: Display “In Stock” Products First @ Shop
    We’ve already seen how to add a custom “Product Sorting” option to the “Default Sorting” dropdown in the WooCommerce Shop page. The task I was presented with, however, was to display items based on a custom “meta key”. Now, if you have no idea what a “meta key” is, don’t worry too much. For example, […]
  • WooCommerce: Show Product Custom Field in the Category Pages
    A client asked me to show a given custom field in the loop (i.e. Shop page, Category pages, Tag pages = anywhere woocommerce products are returned). Interestingly enough, she didn’t want to show the product short description (see “show product short description on the homepage only” snippet) but a custom field, so here’s how you […]

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

17 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

      1. I also do not see this – I also don’t even see custom fields – https://snipboard.io/LqndU3.jpg

        1. Uhm, it may be the new version of WooCommerce hiding those… let me check

          1. No it’s not. In my case it’s ACF hiding it. If you happen to have it too, you can use this quick snippet:

            add_filter( 'acf/settings/remove_wp_meta_box', '__return_false' );
  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? 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 *