Skip Navigation

[Resolved] How to add the meta also to the woocommerce order in admin side

This thread is resolved. Here is a description of the problem and solution.

Problem:

Using Toolset form commerce to submit the form and post custom meta fields, how to add the meta also to the order in wordpress admin side.

Solution:

There isn't such kind of feature within Toolset plugins, it needs custom codes, You might consider the action hook "woocommerce_checkout_create_order_line_item" of Woocommerce plugin, for example:

https://toolset.com/forums/topic/how-add-the-meta-also-to-the-woocommerce-order/#post-1118111

Relevant Documentation:

This support ticket is created 6 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by domenicoS 6 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1118099

Hi, is perfect, thanks.
Just the last thing. How add the meta also to the order as in the image?
Now is added only to the cart.

Thank you Luo for your great support

#1118111

Hello,

Same as your previous tickets, there isn't such kind of feature within Toolset plugins, it needs custom codes, according to our support policy, we don't provide custom codes support:
https://toolset.com/toolset-support-policy/

Here are my suggestions:
You might consider the action hook "woocommerce_checkout_create_order_line_item" of Woocommerce plugin, for example:

/**
 * Display the custom field value in the order admin side
 */
function custom_meta_after_order_itemmeta( $item_id, $item, $product) { 
	$order_id = get_the_ID();
    $cred_meta = get_post_meta( $order_id, '_cred_meta');
	
	$cred_meta = maybe_unserialize( $cred_meta[0] );
	$extra_text = '';
	if(isset($cred_meta[0]['cred_post_id'])){
		$post_id = $cred_meta[0]['cred_post_id'];
		
		$adult_num = get_post_meta($post_id, 'wpcf-adult-number', true);
		$extra_text .= sprintf(
			'<p>%s</p>',
			esc_html( 'Adult number: ' . $adult_num )
		);
	}
	echo $extra_text;
}; 

// add the action
add_action( 'woocommerce_after_order_itemmeta', 'custom_meta_after_order_itemmeta', 10, 3);

See the result here:
hidden link

I am on holidays, you might get delay answer, if you have other new questions, please create new tickets, our other supporters will handle them. thanks

#1119658

My issue is resolved now. Thank you!