Display Product add-ons meta
-
Hi,
I’m using the product add-ons extension.
The values show up in the invoice below the product name; but I’m not being able to display them separately in different parts of the invoice. I’m using this code:$yourfield = get_post_meta($wpo_wcpdf->export->order->id,'Pet Owner',true); if (isset($yourfield)) { echo $yourfield; }Thanks in advance.
https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/
-
Hi Paulo,
Without knowing the meta names, I cannot help you: the ‘Pet Owner’ field might have a different name in the database (‘pet_owner’ for example). What do you see when you go into the edit order screen under the items listed there?Ewout
Hi Ewout,
Thanks for your reply. The names I’m using are:- Name
- Marital Status
Screenshot here:
http://axxostudio.com/paulo/test_screenshots/names1.jpg
ThanksHi Paulo,
I think it’s better if you contact WooThemes for support: I do not know how these values are stored, and without access to the database I can’t tell how you should retrieve these values. WooThemes and/or the developers of this Product add-onsIf you want to dig in yourself, you could access the database, and look in the wp_postmeta table and see if you can find out which meta_key is used for these fields. This meta_key is what you need to fill in where you used ‘Pet Owner’. (assuming you already tried ‘Marital Status’ there!).
One last check to make sure we’re on the same line: if you are fine with the way the fields are currently displayed in the invoice, but you just want them separate from the product listing, you will need to loop through the items again to print them, something like this:
<?php $items = $wpo_wcpdf->get_order_items(); if( sizeof( $items ) > 0 ) { foreach( $items as $item ) { echo $item['meta']; } } ?>Additionally, you could then remove this piece from the packing slip and invoice template:
<span class="item-meta"><?php echo $item['meta']; ?></span>Let me know if you find a solution!
Kind regards,
Ewout FernhoutThanks for the input; I’ll continue my search and let you know.
Perhaps you can help me figure out a new question (separate thread)
Thanks,
PauloHi Ewout,
I found the values stored in the database inside the wp_woocommerce_order_itemmeta table.(see screenshot)
http://axxostudio.com/paulo/test_screenshots/woo_item_meta.gifBut still no luck retrieving the values in my template.
Let me know your thoughts.Thanks,
PauloHi Paulo,
There’s a difference between post meta, which you can get from the order like the code you posted in your first post above, and item meta, which you need to loop through like in my example.Does this work for you?
<?php $items = $wpo_wcpdf->get_order_items(); if( sizeof( $items ) > 0 ) { foreach( $items as $item ) { if (isset($item['item']['item_meta']['Marital Status'])) { echo 'Marital Status: ' . $item['item']['item_meta']['Marital Status'][0] . '<br />'; } if (isset($item['item']['item_meta']['Name'])) { echo 'Name: ' . $item['item']['item_meta']['Name'][0] . '<br />'; } } } ?>Have a great day!
EwoutWorks great Ewout!
Thanks a lot.
PauloHi Ewout,
I’m using this code to display the item meta in the PDF.
$items = $wpo_wcpdf->get_order_items(); if( sizeof( $items ) > 0 ) { foreach( $items as $item ) { if (isset($item['item']['item_meta']['member_info'])) { $member_info = $item['item']['item_meta']['member_info'][0]; } echo $member_info; } }Can you show me how to display data when the field contains an array within the array? IE: member_info has 3 columns (Title, Name, Address) The above code will display:
TitleNameAddressManagerJohn123PresidentMary555Thanks in advance.
PauloHi Paulo,
You can loop through the array with
foreach, and add a break after each echo to put them on separate lines:$items = $wpo_wcpdf->get_order_items(); $items = $wpo_wcpdf->get_order_items(); if( sizeof( $items ) > 0 ) { foreach( $items as $item ) { if (isset($item['item']['item_meta']['member_info'])) { foreach ($item['item']['item_meta']['member_info'] as $key => $value) { echo $key . ': ' . $value . '<br/>'; // for example: Title: Manager } } } }This should work, but I don’t know what your array looks like exactly. If it doesn’t, you can use the following code to display the structure of the array, which will help in debugging:
$items = $wpo_wcpdf->get_order_items(); if( sizeof( $items ) > 0 ) { foreach( $items as $item ) { if (isset($item['item']['item_meta']['member_info'])) { print_r($item['item']['item_meta']['member_info']); } } }Ewout,
I tried the above but it didn’t work. The structure looks like this:
Array ( [0] => TitleNameAddressManagerJohn123PresidentMary555 )
Thanks again,
PauloThis means that the data is not actually saved in the item_meta as an array, but as a single (concatenated) string! How did you input this?
I’m using the List option in Gravity Forms.
http://www.gravityhelp.com/documentation/page/ListI suggest to contact the authors from gravity forms to inform about how to retrieve this tabular data. Perhaps they use some sort of delimiter that is not visible in the above output. It’s also possible that this list option array is not compatible with the WooCommerce item_meta storage.
Let me know if you find out more!
Hi Ewout,
probably you could help me.I’m trying to display just some selected values not all of them.
// Variation
if ( $item_meta->meta ) {
echo ‘
<small>’ . nl2br( $item_meta->display( true, true ) ) . ‘</small>’;
}This code display all item_meta, I need to hide one of them called warranty.
Could you help me?
you can get the item meta in an array:
$item['item']['item_meta']unsetthe warranty meta (print_rthe array first to find out what it’s called)
Then loop through that array to display them.
The topic ‘Display Product add-ons meta’ is closed to new replies.