Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    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

    Thread Starter Paulo Pinto

    (@paulopinto)

    Hi Ewout,
    Thanks for your reply. The names I’m using are:

    • Name
    • Marital Status

    Screenshot here:
    https://axxostudio.com/paulo/test_screenshots/names1.jpg
    Thanks

    Plugin Contributor Ewout

    (@pomegranate)

    Hi 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-ons

    If 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 Fernhout

    Thread Starter Paulo Pinto

    (@paulopinto)

    Thanks 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,
    Paulo

    Thread Starter Paulo Pinto

    (@paulopinto)

    Hi Ewout,
    I found the values stored in the database inside the wp_woocommerce_order_itemmeta table.(see screenshot)
    https://axxostudio.com/paulo/test_screenshots/woo_item_meta.gif

    But still no luck retrieving the values in my template.
    Let me know your thoughts.

    Thanks,
    Paulo

    Plugin Contributor Ewout

    (@pomegranate)

    Hi 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!
    Ewout

    Thread Starter Paulo Pinto

    (@paulopinto)

    Works great Ewout!
    Thanks a lot.
    Paulo

    Thread Starter Paulo Pinto

    (@paulopinto)

    Hi 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: TitleNameAddressManagerJohn123PresidentMary555

    Thanks in advance.
    Paulo

    Plugin Contributor Ewout

    (@pomegranate)

    Hi 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']);
    		}
    	}
    }
    Thread Starter Paulo Pinto

    (@paulopinto)

    Ewout,
    I tried the above but it didn’t work. The structure looks like this:
    Array ( [0] => TitleNameAddressManagerJohn123PresidentMary555 )
    Thanks again,
    Paulo

    Plugin Contributor Ewout

    (@pomegranate)

    This 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?

    Thread Starter Paulo Pinto

    (@paulopinto)

    I’m using the List option in Gravity Forms.
    https://www.gravityhelp.com/documentation/page/List

    Plugin Contributor Ewout

    (@pomegranate)

    I 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?

    Plugin Contributor Ewout

    (@pomegranate)

    you can get the item meta in an array:

    $item['item']['item_meta']

    unset the warranty meta (print_r the array first to find out what it’s called)
    Then loop through that array to display them.

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Display Product add-ons meta’ is closed to new replies.