WooCommerce - excelling eCommerce
order_item_meta (4 posts)

  1. jimlongo
    Posted 2 years ago #

    On my checkout page I'm trying to access data from the wp_woocommerce_order_itemmeta table.

    I've read the woocommerce_order_item_meta function and the WC_Order_Item_Meta class, but nothing I've tried will return anything on the checkout page.

    Does anyone know how i can access this information?

    Thanks for any help.


  2. jimlongo
    Posted 2 years ago #

    I guess you just query the database

    $var = $wpdb->get_var( "
    		SELECT wm.meta_value
    		FROM wp_woocommerce_order_itemmeta wm JOIN
    		wp_woocommerce_order_items wo
    		ON wm.order_item_id = wo.order_item_id
    		WHERE wo.order_item_name = 'MY ITEM'
    		AND wm.meta_key= 'MY KEY'
    		AND wo.order_id = $order->id

    This will return the meta_value from the table for this item in this order.

  3. Paulo Pinto
    Posted 1 year ago #

    I'm having the same trouble retrieving values from that table.
    Did you have any luck resolving the issue?
    Thanks in advance.

  4. brettlefty
    Posted 1 year ago #

    The order item meta is shown on the Edit Order page, so it's definitely possible to retrieve these items.

    Check out these files:
    class-wc-meta-box-order-items.php (lines 23-26, 56-65)
    ...and that file includes this one:
    html-order-item.php (lines 42-67)

    There's probably also some code to display these fields in the order email file:
    class-wc-emails.php (line 283 function order_meta)

    Basically you have to get the order, then get each product in the order, and then pull the meta values for that line item.

    If I knew more about how exactly you want to use this data, I could probably give you some custom code to put it where you want.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce - excelling eCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic