• Resolved crowesnest

    (@crowesnest)


    I would like to update a field that I created in the product options. I have been able to pull the contents from the field but have not been able to update it.

    	$your_phone = $item->get_meta('dinner_phone');
    	$update_phone = wdc_format_phone($your_phone);
    
    	wc_update_order_item_meta($item,'dinner_phone', $update_phone);
    
    	$new_phone = $item->get_meta('dinner_phone');
    

    I haven’t been able to figure out how to get the item id to make this work.

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

    (@themehigh)

    The function used to update the item meta is given below.

    wc_update_order_item_meta( $item_id, $meta_key, $meta_value, $prev_value = '' );

    Please note that you need to pass the item_id.

    The item_id can be obtained from the order object. You can refer the above link for more details:

    https://stackoverflow.com/questions/19499330/how-to-get-order-item-id-woocommerce

    We hope this will help.

    Thank you!

    Thread Starter crowesnest

    (@crowesnest)

    Sorry, but I still don’t get the item_id. I took a look at the stackoverflow link and I must be missing something. Is this what should work?

    foreach ($items as $key => $product ) {
    		$item_id = $key['item_id'];
    		break;
    	}
    Plugin Author ThemeHigh

    (@themehigh)

    Could you please let us know, from where you are referring the $item_id? Also, please provide us more details regarding your requirement.

    Further, the link that we have provided is to get the item_id from the order object.

    Thank you!

    Plugin Author ThemeHigh

    (@themehigh)

    Since we haven’t heard back from you, we hope your issue is resolved.

    We are going to mark this thread as resolved.

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Update a field using PHP’ is closed to new replies.