Hello,
I'm coming back on this ticket : https://toolset.com/forums/topic/hook-for-adding-a-custom-field-in-wc-email/
First of all, I'm not sure the cred_save_data is the right hook to use as this should be done when the order is moving to "In Progress". So, I'm using now the cred_commerce_after_order_completed hook (as the order could be validated manually in the backend, I cannot use the cred_commerce_after_payment_completed). On the WC side, I have seen that 2 hooks could be used : woocommerce_email_order_meta_fields and woocommerce_email_order_meta_keys. What is the difference between these 2 hooks and what is the best one for my current use?
Second, I need to retrieve a custom field which is not in the order, but on the post that have been created thanks to the form. So, I have added the get_post_meta inside to retrieve the $nomevent. Now, how I can pass it to the WC hook? Is it sufficient to put the variable in the 'value' area?
Third, when using this code, I 'm getting a critical error. Could it be that the priorities of each hook have to be done differently ... or is there something else to take into acount?
Last, using the woocommerce_email_order_meta_fields hook, where is displayed the meta fields in the mail?
Here is my code :
function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
$fields['meta_key'] = array(
'label' => __( 'Sujet : ' ),
'value' => $nomevent,
);
return $fields;
}
add_action('cred_commerce_after_order_completed','func_set_featured_product',10,2);
function func_set_featured_product($post_id,$form_data) {
if ($form_data['id']==755) {
$nomevent = get_post_meta( $nom_id, 'wpcf-nom-de-l-evenement', true );
add_filter( 'woocommerce_email_order_meta_fields', 'custom_woocommerce_email_order_meta_fields', 10, 3 );
}
}
Regards
Pat