Hi guys,
We're trying to create a custom loop that pulls additional 'meta_key' information from the '_woocommerce_order_itemmeta' table. In the default Views Loop we see that the following WooCommerce 'product' fields/post meta are able to be inserted into the loop:
* Add to cart button - product listing pages
* Product price
* Add to cart button - single product page
* Product image
* Add to cart message
* Product tabs - single product page
* Onsale badge
* Product attributes
* Related Products
* Product Rating - single product page
* Product Rating - product listing pages
* Product Category Image
* Product Upsell
* Breadcrumb
* Product meta
* Cart Count
* Reviews
What we've done so far: because WooCommerce registers their post types as not public (i.e. 'public' => false), we've added the following to our functions.php file to be able to pull in 'orders' post types into the Views Loop:
add_filter( 'woocommerce_register_post_type_shop_order', function ( $args ) {
$args['public'] = true;
return $args;
});
However, what we're not clear on is how to get additional meta_key values recognized by Views (for instance the '_qty' meta key value from the _woocommerce_order_itemmeta table. We do know that we can write a shortcode and then add that shortcode under the 'Views > Compatability' setting, but we're not sure if that's the right approach both from a performance and ease-of-implementation perpective.
As such could you please guide us on how we can get additional meta_key values for CPTs recognized in the Views loop?
Thanks in advance!
Hidden Custom fields can be added to Views under Views > Settings > Hidden custom fields.
That will make the Fields visible in the Query Options and in the Post field section when inserting ShortCodes in a View Loop Editor.
Otherwise a ShortCode is always a good approach as it gets triggered only when you / where you insert it, but with above approach you should be fine too.
Please let me know if the above solution works for you, I look forward to your reply!
Thank you for your patience.