Yes Luo, I see the field as you explain. But I need to see this data in the woocommerce meta for the reason that I explain at the beginning of this post. My partner who manage the product cannot have access to the backend.
So is important to display this meta in the woocommerce meta in the frontend and also in the backend.
A share with you screenshots to see where data need to be displayed.
Hope it helps
That is completed different problem, see your original question:
https://toolset.com/forums/topic/how-is-possible-to-save-it-in-the-woocommerce-order-meta/#post-1115456
You are asking for the meta fields of order post, so I setup the demo for updating custom fields of order post
But those screenshots you mentioned above are in Woocommerce cart page, in the cart page, the woocommerce order post isn't created.
In your case, it needs other custom codes, I searched it in google, find this thread:
hidden link
See sections "Adding custom values to the cart" and "Displaying custom fields in the cart and checkout"
hidden link
hidden link
My qustion was this:
"Data as number of people and number of child, ecc ar very important. How is possible to save it in the woocommerce order meta? should be great to have the possibility to call this data in the order detail and in the order email which my partner received automaticcally by woocommerce. My partner don't have access to the backend and to my-order custom post, but only to the detail of woocommerce order. At the moment in this detail there is only the final price, they cannot know how many adults, childs acc."
And i was reffering to the order post meta from the beginning.
I tried with this code ad in the example you shared with me, but I'm not able to see the adult number as in the screenshot:
function cfwc_add_custom_field_item_data( $cart_item_data, $product_id, $variation_id, $quantity ) {
if( ! empty( $_POST['wpcf-adult-number'] ) ) {
// Add the item data
$cart_item_data['title_field'] = $_POST['wpcf-adult-number'];
}
return $cart_item_data;
}
add_filter( 'woocommerce_add_cart_item_data', 'cfwc_add_custom_field_item_data', 10, 4 );
function cfwc_cart_item_name( $name, $cart_item, $cart_item_key ) {
if( isset( $cart_item['wpcf-adult-number'] ) ) {
$name .= sprintf(
'<p>%s</p>',
esc_html( $cart_item['wpcf-adult-number'] )
);
}
return $name;
}
add_filter( 'woocommerce_cart_item_name', 'cfwc_cart_item_name', 10, 3 );
I have added below codes in your theme file "functions.php":
/**
* Display the custom field value in the cart
*/
function cfwc_cart_item_name( $name, $cart_item, $cart_item_key ) {
if($cart_item['cred_meta']['cred_form_id'] != 24662 || !isset($cart_item['cred_meta']['cred_post_id']))return; //24662 is the Toolset form ID
$post_id = $cart_item['cred_meta']['cred_post_id'];
$adult_num = get_post_meta($post_id, 'wpcf-adult-number', true);
$name .= sprintf(
'<p>%s</p>',
esc_html( 'Adult number: ' . $adult_num )
);
return $name;
}
add_filter( 'woocommerce_cart_item_name', 'cfwc_cart_item_name', 10, 3 );
Please test again, and it is only a demo for your reference.
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
My issue is resolved now. Thank you!
Hi Luo,
I've to add the same filter with another id-form.
The original is:
if($cart_item['cred_meta']['cred_form_id'] != 24662 || !isset($cart_item['cred_meta']['cred_post_id']) ) || return $name;
How I've to change the code? I tryed wuth this, but is does not works
if($cart_item['cred_meta']['cred_form_id'] != 24662 || $cart_item['cred_meta']['cred_form_id'] != 25474 || !isset($cart_item['cred_meta']['cred_post_id']) ) || return $name;