• Resolved MCI Desarrollo

    (@mcidesarrollo)


    Hello, we have created a plugin that sends automatic emails with the cart_items of an order but the fields of your plugin are not being added.
    How can I get the extra fields from a cart_item or an order_item to incorporate it into my plugin?

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author ThemeHigh

    (@themehigh)

    The fields created using our plugin are saved using the function wc_add_order_item_meta( $item_id, $meta_key, $meta_value, $unique = false ) .

    You can retrieve the value of the fields from the database by using the below function.

    wc_get_order_item_meta( $item_id, $key, $single = true )

    We hope this will help.

    Thank you!

    Thread Starter MCI Desarrollo

    (@mcidesarrollo)

    Thank you very much for the reply!

    I am trying to access the order values but I cannot. I’m doing it like this but it doesn’t work. What am I doing wrong?

    $order = wc_get_order( $order_id );
    foreach ($order->get_items() as $item_id => $item_obj) {

    $res= $item_obj->get_meta_data();

    foreach ($res as $key => $value) {
    foreach ($value as $key2 => $value2) {
    echo $key2.’->’.$value2.'<br>’;
    }
    }
    }

    Thread Starter MCI Desarrollo

    (@mcidesarrollo)

    I am also trying to do it like this:

    $order = wc_get_order(802);

    foreach ($order->get_items() as $item_id => $item_obj) {

    $res = $item_obj->get_meta_data();

    foreach ($res as $key22 => $value22) {

    $res2 = wc_get_order_item_meta($item_id, $key22, true);

    foreach ($res2 as $key33 => $value33) {

    foreach ($value33 as $key44 => $value44) {

    $res3 = wc_get_order_item_meta($item_id, $key44, true);

    foreach ($res3 as $key55 => $value55) {

    var_dump($value55);
    }
    }
    }
    }
    }

    Plugin Author ThemeHigh

    (@themehigh)

    You can refer to the below sample code.

    add_action( 'woocommerce_order_details_after_order_table', 'get_custom_field_value', 10, 1 );
    
    function get_custom_field_value($order){
      $value = wc_get_order_item_meta($order->id, 'custam_field_name', true);
      echo 'Label :' .$value;
    }

    We hope this will help.

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get fields from a cart item’ is closed to new replies.