[Résolu] Hook for adding a custom field in WC email
This support ticket is created Il y a 3 années et 7 mois. 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I have a site with Toolset and WC. As it is not possible to manage variable products in front end with Toolset, I'm trying to find a workaround.
Inside the standard WC product, I have inserted a WC forms that enables to chose between different products (here, these products are just used to define the price of the initial product).
No issue until there, but now, I need to insert the title of the initial product inside the WC emails. For this, WC propose a hook :
/**
* Add a custom field (in an order) to the emails
*/
add_filter( 'woocommerce_email_order_meta_fields', 'custom_woocommerce_email_order_meta_fields', 10, 3 );
function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
$fields['meta_key'] = array(
'label' => __( 'Label' ),
'value' => get_post_meta( $order->id, 'meta_key', true ),
);
return $fields;
}
In addition, only some specific products should be managed like this (the single products do not need it and should be treated as a standard products).
My question is : how can I merge the WC hook in the same time than a cred_save_data hook that will be created for the specific Forms that will be used ?
Hello. Thank you for contacting the Toolset support.
Do you mean that you want to run/trigger the hook you added "woocommerce_email_order_meta_fields" when you have variable product? If yes:
As this is a standard WC hook I suggest you should contact WC support as there is no way to merge two hooks that is standard WC hook and Toolset cred_save_data hook.
Thanks for coming back.
Perhaps I did not have been clear : I want that the "cred_save_data" issued by the Forms lauch in the same time the "woocommerce_email_order_meta_fields" function in orde rto add the related fields to the current order.
Hope this clarify the need.
Regards
Pat