Support » Plugin: WooCommerce » order_item_meta

  • jimlongo


    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • jimlongo


    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.

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

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘order_item_meta’ is closed to new replies.