Add the following code to your current theme’s function.php
// # Note : In this example {agent_email} is the merge tag you want to use when you configure the email or advanced email settings.
// # This should return the agent email. Supposing you have multiple agent email, you have to add them in
function agent_additional_email_meta_tags( $tags ){
$tags['{agent_email}'] = 'Assigned Agent Email';
$tags['{agent_email_1}'] = 'Agent Email Ph#1';
$tags['{agent_email_2}'] = 'Agent Email Ph#2';
$tags['{agent_email_3}'] = 'Agent Email Ph#3';
return $tags;
}
add_filter( 'wpc_email_meta_tags', 'agent_additional_email_meta_tags' );
// # Note: Add the following code in your current themes functions.php
// # This code will enable you to fetch the email value for the merge tag you have used above
// # The query should be the same as the meta key you have used in the custom fields.
function wpcargo_email_replace_shortcodes_list_agent( $replace_shortcodes, $post_id ){
$delimiter = array("{", "}");
$replace_shortcodes = array();
if( !empty( wpcargo_email_shortcodes_list() ) ){
foreach ( wpcargo_email_shortcodes_list() as $shortcode => $shortcode_label ) {
$shortcode = trim( str_replace( $delimiter, '', $shortcode ) );
if( $shortcode == wpcargo_track_meta() ){
$replace_shortcodes[] = esc_html( get_the_title($post_id) );
}elseif( $shortcode == 'admin_email' ){
$replace_shortcodes[] = apply_filters( 'wpcargo_admin_notification_email_address', get_option('admin_email') );
}elseif( $shortcode == 'site_name' ){
$replace_shortcodes[] = esc_html( get_bloginfo('name') );
}elseif( $shortcode == 'site_url' ){
$replace_shortcodes[] = esc_url( get_bloginfo('url') );
}elseif( $shortcode == 'status' ){
$replace_shortcodes[] = esc_html( get_post_meta( $post_id, 'wpcargo_status', true ) );
}elseif( $shortcode == 'wpcreg_client_email' ){
$reg_shipper = (int) esc_html( get_post_meta( $post_id, 'registered_shipper', true ) );
$user_info = get_userdata($reg_shipper);
$reg_email = '';
if( $user_info ){
$reg_email = $user_info->user_email;
}
$replace_shortcodes[] = $reg_email;
}elseif( $shortcode == 'agent_email' ){
$agent = (int) esc_html( get_post_meta( $post_id, 'agent_fields', true ) );
$user_info = get_userdata($agent);
$reg_email = '';
if( $user_info ){
$reg_email = $user_info->user_email;
}
$replace_shortcodes[] = $reg_email;
}elseif( $shortcode == 'agent_email_1' ){
$reg_email= esc_html( get_post_meta( $post_id, 'agent-1', true ) );
$replace_shortcodes[] = $reg_email;
}elseif( $shortcode == 'agent_email_2' ){
$reg_email= esc_html( get_post_meta( $post_id, 'agent-2', true ) );
$replace_shortcodes[] = $reg_email;
}elseif( $shortcode == 'agent_email_3' ){
$reg_email= esc_html( get_post_meta( $post_id, 'agent-3', true ) );
$replace_shortcodes[] = $reg_email;
}else{
$meta_value = maybe_unserialize( get_post_meta( $post_id, $shortcode, true ) );
$meta_value = apply_filters( 'wpcargo_shortcode_meta_value', $meta_value, $shortcode, $post_id );
if( is_array( $meta_value ) ){
$meta_value = implode(', ',$meta_value );
}
$replace_shortcodes[] = esc_html( $meta_value );
}
}
}
return $replace_shortcodes;
}
add_filter( 'wpcargo_email_replace_shortcodes_list', 'wpcargo_email_replace_shortcodes_list_agent', 10, 2 );