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

    (@pomegranate)

    Hi John,
    It depends on what you mean by order item meta. In the default template, all item meta should already be printed!

    <?php echo $item['meta']; ?>

    Is it something else you want to display? Let me know!

    Ewout

    Thread Starter John

    (@astutejk)

    Thanks Ewout,

    I didn’t want all of it. I store a few bits and bobs in there.

    I managed to get what I wanted with
    wc_get_order_item_meta( $item_id, $key, $single = true )
    bit.ly/1LnkRWb
    to display in a custom invoice template.

    Awesome plug-in by the way…
    cheers!

    Plugin Contributor Ewout

    (@pomegranate)

    Hi John,
    Great solution, thanks for sharing!

    Ewout

    I still don’t get how to use wc_get_order_item_meta() though. Can anybody give an example?

    Plugin Contributor Ewout

    (@pomegranate)

    Hi Nyenius,
    I can imagine :o) The code posted is not an example code but the function with its relavant parameters.

    Here’s an example using meta named ‘Color’:

    <?php
    $meta_key = 'Color';
    echo wc_get_order_item_meta( $item_id, $meta_key, true );
    ?>

    Or if you want to use the pdf template action hooks (rather than a custom template):

    add_action( 'wpo_wcpdf_after_item_meta', 'wpo_wcpdf_custom_meta', 10, 3 );
    function wpo_wcpdf_custom_meta ( $template_type, $item, $order ) {
        $meta_key = 'Color';
        echo wc_get_order_item_meta( $item['item_id'], $meta_key, true );
    }

    Hope that helps – enjoy the weekend!
    Ewout

    Hi Ewout,

    I’m trying to get a specific attribute value that I want to display in an e-mail. So this is my code that I use to get the product info from the order and send by e-mail.

    foreach($order_items as $product) {
    	$price = $order->get_item_total($product, false, false);
            $message .= 'product_' . $product['product_id'] . '_name,' . $product['name'] . '<br>';
            $message .= 'product_' . $product['product_id'] . '_qty,' . $product['qty'] . '<br>';
            $message .= 'product_' . $product['product_id'] . '_total_price,' . wc_format_decimal($price) . '<br><br>';
        }

    After the product name I want to display the attribute ‘size’. Any idea how I should do this?

    Thx!

    Plugin Contributor Ewout

    (@pomegranate)

    Hi! I recommend installing the WooCommerce Store Toolkit so you can find out whether the ‘size’ is stored in the item meta. If it’s really an attribute, check the docs here: Displaying product attributes

    Hope that helps!
    Ewout

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Display order item meta data in custom invoice template – how?’ is closed to new replies.