Customizing footer text email notiications based on user role in Woocommerce
// Setting the Order ID as a global variable add_action('woocommerce_email_before_order_table', 'email_order_id_as_a_global', 1, 4); function email_order_id_as_a_global($order, $sent_to_admin, $plain_text, $email){ $GLOBALS['order_id_str'] = $order->get_id(); } // Conditionally customizing footer email text add_action( 'woocommerce_email_footer_text', 'custom_email_footer_text', 10, 1 ); function custom_email_footer_text( $get_option ){ // Getting the email Order ID global variable $refNameGlobalsVar = $GLOBALS; $order_id = $refNameGlobalsVar['order_id_str']; // If empty email Order ID we exit if( empty($order_id) ) return; //Get the customer ID $user_id = get_post_meta( $order_id, '_customer_user', true ); // Get the user data $user_data = get_userdata( $user_id ); if ( in_array( 'wholesale_customer', $user_data->roles ) ) { $get_option = 'Store 1'; } else { $get_option = 'Store 2'; } return $get_option; }
Code goes in function.php file of the active child theme (or active theme).
Tested and works. It should also work for you.