I’m using WP WooCommerce and I want to add custom product fields that shall be used in conjunction with the API Client Lib.
I followed this guide to the end and everything works fine, except for reading the data. Now, I’m using the API Client Library for processing the orders where I want to fetch this meta information of the products. But how to I access this information? Since my script does not run within the WP loop, I can’t access any get_post_meta function or the like. It is also not listed in the product meta, I get from the API (and I don’t understand why).
The only solution I see right now is to get the data directly from the wp_postmeta table in MySQL. Is this correct or is there any other, more elegant, way to get this data?
Thx for any help.
Edit: I use workaround for this problem now. Since there is seemingly no way to access the product meta data outside of the loop, I now use WP’s native custom fields to retrieve that data. In contrary to the WC product meta data the WP custom field can be accessed via the WC API. The data sits in the parent of my product, so I can access it by making a second API call for the parent.