Call Xprofile Field Data into Appointments+ notification email
-
Hello I’m trying to Call Xprofile Field Data into the Appointments+ notification email
I have create an xprofile field with id 206 and I am also using WPMU appointments+ Within that there is a email notification template section where you can insert PlaceHolder code to pull the users info into the emails. They have some built in but I need to add a new one
I have made a new field and want to add USERS_PHONE to the placeholder system.
this is the code snippet im working in
$customerUser = get_userdata($r->user);
$artistUser = get_userdata($r->worker);$args = array(
‘user’ => $r->name,
‘customer_username’=>$customerUser->user_login,
‘artist_username’=>$artistUser->user_login,
‘service’ => $appointments->get_service_name( $r->service ),
‘worker’ => appointments_get_worker_name( $r->worker ),
‘datetime’ => $r->start,
‘price’ => $r->price,
‘deposit’ => $appointments->get_deposit( $r->price ),
‘phone’ => $r->phone,
‘note’ => $r->note,
‘address’ => $address,
’email’ => $email,
‘city’ => $r->city,
‘number_of_guest’=>$r->number_of_guest,
‘travel_type’=>$travel_type,
‘ID’=>$r->ID
);Now I’ve used <?php echo xprofile_get_field_data(‘206’); ?> and can show the info within a page template but do not know how to make the above code work. My disconnect is how to pull the xprofile data into this snippet and then call the data to show in the email. I will use USERS_PHONE in the email template to call the data
-
I’ve got a plugin called BP Profile Shortcodes Extra that has a shortcode to display the value of an xprofile field, you could take a look at how I did that and use that as a basis for your code?
Thank you so much for replying. There is quite a lot of data on the plugin page. I need to display it within a backend email template. I am already able to show xprofile fields on the profile. Any ideas?
Sorry I’ve no idea how to pull it into the email template.
So what you do is create a shortcode similar to what you did for the profile pages but it’s within the appointments+ files. I can adjust the code to create the shortcode USER_PHONEr . Here is an example of custom code for a drop down on profile that was included into email templates
if($r->travel_type==2){
$address=$r->address;
$travel_type=”Photographer Travel to Me”;
} else {
$sql = “SELECT * FROMwppl_friends_locator
where member_id=”.$r->worker;$squad=$wpdb->get_results( $sql );
if($squad){
$address=$squad[0]->formatted_address;
}
else{
$address=””;
}
$travel_type=”Travel to Photographer”;
}but instead of all the travel type and address stuff I need to call the xprofile fields database then find id 206 and display that info.
Thank You
the fields are $user_phone and $worker_phone
$user_phone is xprofile id 206 and $worker_phone is xprofile is id 7
add_action(‘bp_after_profile_edit_content’,’edit_appointment_settings_xprofile’);
// Displays Editable Fields for Appointments+ email and phone
function edit_appointment_settings_xprofile(){
// Only Logged in users can make these edits
$profileuser = wp_get_current_user();?>
<h3><?php _e(“Appointments+ Settings”, ‘appointments’); ?></h3>
<form method=”post” action =” “id=”appointment-edit-form” class=”standard-form”>
<table class=”form-table”>
<tr>
<th><label><?php _e(“My email for A+”, ‘appointments’); ?></label></th>
<td>
<input type=”text” style=”width:25em” name=”app_email” value=”<?php echo get_user_meta( $profileuser->ID, ‘app_email’, true ) ?>” <?php echo $is_readonly ?> />
</td>
</tr>
<tr>
<th><label><?php _e(“My Phone”, ‘appointments’); ?></label></th>
<td>
<input type=”text” style=”width:25em” name=”app_phone” value=”<?php echo get_user_meta( $profileuser->ID, ‘app_phone’, true ) ?>”<?php echo $is_readonly ?> />
</td>
</tr>
<input name=”action” type=”hidden” value=”save_xprofile” />
// Add other fields like location etc .. here if needed</table>
<div class=”submit”>
<input type=”submit” action = “” name=”appointment-edit-form-submit” id=”appointment-edit-form-submit” value=”Save” />
</div>
<?
}thank you zimou13 but I don’t see how this would help me. Seems like a form?
anybody have any ideas? Venutius I’ll pay to help me.
I don’t have WPMU Appointments, or a clear understanding of your requirements. Have yu tried asking WPMU?
they don’t help they are so slow. The only requirements are calling the xprofile fields into a template file
I think the key to what you want to do revolves around this:
global $wpdb; $user_id = ?? $user_phone = $wpdb->get_col("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 206 AND user_id = $user_id"); $worker_phone = $wpdb->get_col("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 7 AND user_id = $user_id");
Does the template have a way of passing the user id to be used?
I believe the user is is already pulled because we show username, links to profile pages in email template already.
There is a notification file but I already called USER_PHONE AND WORKER_PHONE. Correctly into this file.
$replacement = array( '/\bSITE_NAME\b/U' => wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), '/\bCLIENT\b/U' => $args['user'], '/\bCUSTOMER_USERNAME\b/U'=> $args['customer_username'], '/\bARTIST_USERNAME\b/U' => $args['artist_username'], '/\bSERVICE_PROVIDER\b/U' => $args['worker'], '/\bSERVICE\b/U' => preg_replace( '/\$(\d)/', '\\\$$1', $args['service'] ), '/\bDATE_TIME\b/U' => mysql2date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $args['datetime'] ), '/\bORDER_ID\b/U' => $args['ID'], '/\bTRAVEL_TYPE\b/U' => $args['travel_type'], '/\bUSER_PHONE\b/U' => $args['user_phone'], '/\bWORKER_PHONE\b/U' => $args['worker_phone'],
This basically sets the SHORTCODE for use in admin notification email template section.
I think I also need to add some code to the functions.php file of my theme. I see some other coding in functions.php from my past developer but it may not be related to the notification parts.
$profile_name=xprofile_get_field_data( 'Profile Name' , $user_id ); if($profile_name!=""){ global $wpdb; $query="select * from {$wpdb->prefix}bp_xprofile_data"; $phone=$wpdb->get_results($query); if(count($phone)>0){ $arr=array(); foreach($phone as $service){ $arr[]= $service->ID; $arr2=array( 'service_id' => $service->ID, 'provider_id' => $user_id, 'additional_price' => 0 ); $wpdb->insert( "{$wpdb->prefix}app_service_additional_price", $arr2); }
I don’t understand how we can change this to bp_xprofile_data all I need to call at this point is the phone data id 206 and 7 the field title is Phone.
This is what I have in my confirmation template but not working error line user phone and worker phone
$User_phone = get_userdata($r->phoneuser); $Worker_phone = get_userdata($r->phoneworker); $args = array( 'user' => $r->name, 'customer_username'=>$customerUser->user_login, 'artist_username'=>$artistUser->user_login, 'service' => $appointments->get_service_name( $r->service ), 'worker' => appointments_get_worker_name( $r->worker ), 'datetime' => $r->start, 'price' => $r->price, 'deposit' => $appointments->get_deposit( $r->price ), 'phone' => $r->phone, 'user_phone' => $User_phone->user_login, 'worker_phone' => $Worker_phone->user_login, 'phoneuser' => $wpdb->get_col("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 206 AND user_id = $user_id"); 'phoneworker' => $wpdb->get_col("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 7 AND user_id = $user_id"); 'note' => $r->note, 'address' => $address, 'email' => $email, 'city' => $r->city, 'number_of_guest'=>$r->number_of_guest, 'travel_type'=>$travel_type, 'ID'=>$r->ID );
I also tried this which did not show errors but just didn’t work
$User_phone = $wpdb->get_col("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 206 AND user_id = $user_id"); $Worker_phone = $wpdb->get_col("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 7 AND user_id = $user_id"); $args = array( 'user' => $r->name, 'customer_username'=>$customerUser->user_login, 'artist_username'=>$artistUser->user_login, 'service' => $appointments->get_service_name( $r->service ), 'worker' => appointments_get_worker_name( $r->worker ), 'datetime' => $r->start, 'price' => $r->price, 'deposit' => $appointments->get_deposit( $r->price ), 'phone' => $r->phone, 'user_phone' => $User_phone->user_login, 'worker_phone' => $Worker_phone->user_login, 'note' => $r->note, 'address' => $address, 'email' => $email, 'city' => $r->city, 'number_of_guest'=>$r->number_of_guest, 'travel_type'=>$travel_type, 'ID'=>$r->ID );
Try this:
$wpdb->get_col("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 7 AND user_id = $r->ID);
I’m making a big assumption here, that ID is the users ID, it may not be. another way would be this:
$user_id = bp_core_get_userid( $username = $r->name ); $wpdb->get_col("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 7 AND user_id = $user_id);
I’m not sure if putting the function call inside the Querystring would work, but you could give it a try.
So here’s what I have done.
if I set it like this
$User_phone = get_userdata($r->user); $Worker_phone = get_userdata($r->worker); $args = array( 'user' => $r->name, 'customer_username'=>$customerUser->user_login, 'artist_username'=>$artistUser->user_login, 'service' => $appointments->get_service_name( $r->service ), 'worker' => appointments_get_worker_name( $r->worker ), 'datetime' => $r->start, 'price' => $r->price, 'deposit' => $appointments->get_deposit( $r->price ), 'phone' => $r->phone, 'user_phone' => $User_phone->user_login, 'worker_phone' => $Worker_phone->user_login, 'note' => $r->note, 'address' => $address, 'email' => $email, 'city' => $r->city, 'number_of_guest'=>$r->number_of_guest, 'travel_type'=>$travel_type, 'ID'=>$r->ID );
and I set USER_PHONE and WORKER_PHONE in my email templates is shows the correct usernames or worker name of each user or worker in the emails so the shortcode setup works it’s just the data on the right .
so It would seem what need to be changed is this
'user_phone' => $User_phone->user_login, 'worker_phone' => $Worker_phone->user_login,
but if I change to
$User_phone->user_login, to $wpdb->get_col(“SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 7 AND user_id = $r->ID”),
you were missing the closing ” and I can’t put ; it has to be , at the end
it shows no errors just shows blank on the email.
here is the entire confirmation email template
<?php class Appointments_Notifications_Confirmation extends Appointments_Notification { /** * Send confirmation email to customer, admin and worker * * @param integer $app_id Appointment ID * * @return bool True if emails were sent */ public function send( $app_id ) { $appointments = appointments(); $app = appointments_get_appointment( $app_id ); if ( ! $app ) { return false; } $options = appointments_get_options(); $send_confirmation = 'yes' === $options["send_confirmation"]; $send_confirmation = apply_filters( 'appointments_send_confirmation', $send_confirmation, $app_id ); if ( ! $send_confirmation ) { return false; } $sent_to = array(); $customer_email = $app->get_customer_email(); $result = $this->customer( $app_id, $customer_email ); if ( $result ) { $sent_to[] = $customer_email; $admin_email = $appointments->get_admin_email(); if ( ! in_array( $admin_email, $sent_to ) && $this->admin( $app_id, $admin_email ) ) { $sent_to[] = $admin_email; } $worker_email = $appointments->get_worker_email( $app->worker ); if ( ! in_array( $worker_email, $sent_to ) ) { $this->admin( $app_id, $worker_email ); } return true; } return $result; } /** * Sends a confirmation email to the customer * * @param int $app_id Appointment ID * @param string $email Email to send to * * @return bool True if the email has been sent */ public function customer( $app_id, $email ) { $appointments = appointments(); $r = appointments_get_appointment( $app_id ); if ( ! $r ) { return false; } if ( ! is_email( $email ) ) { $this->manager->log( sprintf( __( 'Unable to notify the client about the appointment ID:%s confirmation, stopping.', 'appointments' ), $app_id ) ); return false; } $template = $this->get_customer_template( $app_id, $email ); if ( ! $template ) { return false; } $attachments = apply_filters( 'app_confirmation_email_attachments', '', $app_id ); $mail_result = wp_mail( $email, $template['subject'], $template['body'], $appointments->message_headers(), $attachments ); if ( ! $mail_result ) { return false; } $this->manager->log( sprintf( __('Confirmation message sent to %s for appointment ID:%s','appointments'), $r->email, $app_id ) ); do_action( 'app_confirmation_sent', $template['body'], $r, $app_id, $email ); return true; } /** * Send a confirmation email to admin * * @param $app_id * @param $admin_email * * @return bool */ public function admin( $app_id, $admin_email ) { $appointments = appointments(); $r = appointments_get_appointment( $app_id ); if ( ! $r ) { return false; } $disable = apply_filters( 'app_confirmation_disable_admin', false, $r, $app_id, $admin_email ); if ( $disable ) { return true; } if ( ! is_email( $admin_email ) ) { return false; } $template = $this->get_admin_template( $app_id ); if ( ! $template ) { return false; } $result = wp_mail( $admin_email, $template['subject'], $template['body'], $appointments->message_headers() ); if ( $result ) { do_action( 'appointments_confirmation_admin_sent', $admin_email, $app_id, $template['body'], $template['subject'] ); } return $result; } public function get_admin_template( $app_id ) { global $wpdb; $appointments = appointments(); $r = appointments_get_appointment( $app_id ); if ( ! $r ) { return false; } $customer_email = $r->get_customer_email(); if ( ! $customer_email ) { return false; } /*$provider_add_text = sprintf( __('A new appointment has been made on %s. Below please find a copy of what has been sent to your client:', 'appointments'), get_option( 'blogname' ) ); $provider_add_text .= "\n\n\n"; $subject = __('New Appointment','appointments');*/ /*Added by */ $options = appointments_get_options(); $subject = $options["confirmation_subject_artist"]; $provider_add_text = $options['confirmation_message_artist']; if($r->travel_type==2){ $address=$r->address; $travel_type="Photographer Travel to Me"; } else { $sql = "SELECT * FROM <code>wppl_friends_locator</code> where member_id=".$r->worker; $squad=$wpdb->get_results( $sql ); if($squad){ $address=$squad[0]->formatted_address; } else{ $address=""; } $travel_type="Travel to Photographer"; } $customerUser = get_userdata($r->user); $artistUser = get_userdata($r->worker); $User_phone = get_userdata($r->user); $Worker_phone = get_userdata($r->worker); $args = array( 'user' => $r->name, 'customer_username'=>$customerUser->user_login, 'artist_username'=>$artistUser->user_login, 'service' => $appointments->get_service_name( $r->service ), 'worker' => appointments_get_worker_name( $r->worker ), 'datetime' => $r->start, 'price' => $r->price, 'deposit' => $appointments->get_deposit( $r->price ), 'phone' => $r->phone, 'user_phone' => $User_phone->user_login, 'worker_phone' => $Worker_phone->user_login, 'note' => $r->note, 'address' => $address, 'email' => $email, 'city' => $r->city, 'number_of_guest'=>$r->number_of_guest, 'travel_type'=>$travel_type, 'ID'=>$r->ID ); $provider_add_text = $this->replace_placeholders( $provider_add_text, $args, 'confirmation-body', $r ); /*end Added by */ $body = $this->get_customer_template( $app_id, $customer_email ); return array( 'subject' => $subject, 'body' => $provider_add_text ); } public function get_customer_template( $app_id, $email ) { global $wpdb; $appointments = appointments(); $r = appointments_get_appointment( $app_id ); if ( ! $r ) { return false; } $options = appointments_get_options(); $body = $options['confirmation_message_customer']; if($r->travel_type==2){ $address=$r->address; $travel_type="Photographer Travel to Me"; } else { $sql = "SELECT * FROM <code>wppl_friends_locator</code> where member_id=".$r->worker; $squad=$wpdb->get_results( $sql ); if($squad){ $address=$squad[0]->formatted_address; } else{ $address=""; } $travel_type="Travel to Photographer"; } $customerUser = get_userdata($r->user); $artistUser = get_userdata($r->worker); $Worker_phone = get_userdata($r->worker); $args = array( 'user' => $r->name, 'customer_username'=>$customerUser->user_login, 'artist_username'=>$artistUser->user_login, 'service' => $appointments->get_service_name( $r->service ), 'worker' => appointments_get_worker_name( $r->worker ), 'datetime' => $r->start, 'price' => $r->price, 'deposit' => $appointments->get_deposit( $r->price ), 'phone' => $r->phone, 'worker_phone' => $Worker_phone->user_login, 'note' => $r->note, 'address' => $address, 'email' => $email, 'city' => $r->city, 'number_of_guest'=>$r->number_of_guest, 'travel_type'=>$travel_type, 'ID'=>$r->ID ); $body = $this->replace_placeholders( $body, $args, 'confirmation-body', $r ); $body = $appointments->add_cancel_link( $body, $app_id ); $body = apply_filters( 'app_confirmation_message', $body, $r, $app_id ); $subject = $options["confirmation_subject_customer"]; $subject = $this->replace_placeholders( $subject, $args, 'confirmation-subject', $r ); return array( 'subject' => $subject, 'body' => $body ); } }
thank you again
any chance you can skype and I can just show the files
help please anyone?
$wpdb->get_col
returns an array
$wpdb->get_var
returns a single value – try itso none of these work
$wpdb->get_var(“SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 206 AND user_id = $r->ID”);
$wpdb->get_col(“SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 206 AND user_id = $r->ID”);
$wpdb->get_results(“SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 206 AND user_id = $r->ID”);
I think something is still missing
I have faith in the community that someone wants to make some money to help me show an xprofile field inside appointments+ email notification template.
Who wants $$$$$
hello,
add_action(‘bp_after_profile_edit_content’,’edit_appointment_settings_xprofile’);// Displays Editable Fields for Appointments+ email and phone
function edit_appointment_settings_xprofile(){
// Only Logged in users can make these edits
$profileuser = wp_get_current_user();?>
<h3><?php _e(“Appointments+ Settings”, ‘appointments’); ?></h3>
<form method=”post” action =” “id=”appointment-edit-form” class=”standard-form”>
<table class=”form-table”>
<tr>
<th><label><?php _e(“My email for A+”, ‘appointments’); ?></label></th>
<td>
<input type=”text” style=”width:25em” name=”app_email” value=”<?php echo get_user_meta( $profileuser->ID, ‘app_email’, true ) ?>” <?php echo $is_readonly ?> />
</td>
</tr>
<tr>
<th><label><?php _e(“My Phone”, ‘appointments’); ?></label></th>
<td>
<input type=”text” style=”width:25em” name=”app_phone” value=”<?php echo get_user_meta( $profileuser->ID, ‘app_phone’, true ) ?>”<?php echo $is_readonly ?> />
</td>
</tr>
<input name=”action” type=”hidden” value=”save_xprofile” />
// Add other fields like location etc .. here if needed</table>
<div class=”submit”>
<input type=”submit” action = “” name=”appointment-edit-form-submit” id=”appointment-edit-form-submit” value=”Save” />
</div>
<?
regards
omkar
https://luckypatcher.pro/ https://kodi.software https://plex.software/Hey this is how you can do it:
?>
<h3><?php _e(“Appointments+ Settings”, ‘appointments’); ?></h3>
<form method=”post” action =” “id=”appointment-edit-form” class=”standard-form”>
<table class=”form-table”>
<tr>
<th><label><?php _e(“My email for A+”, ‘appointments’); ?></label></th>
<td>
<input type=”text” style=”width:25em” name=”app_email” value=”<?php echo get_user_meta( $profileuser->ID, ‘app_email’, true ) ?>” <?php echo $is_readonly ?> />
</td>
</tr>
<tr>
<th><label><?php _e(“My Phone”, ‘appointments’); ?></label></th>
<td>
<input type=”text” style=”width:25em” name=”app_phone” value=”<?php echo get_user_meta( $profileuser->ID, ‘app_phone’, true ) ?>”<?php echo $is_readonly ?> />
</td>
</tr>
<input name=”action” type=”hidden” value=”save_xprofile” />
// Add other fields like location etc .. here if needed</table>
<div class=”submit”>
<input type=”submit” action = “” name=”appointment-edit-form-submit” id=”appointment-edit-form-submit” value=”Save” />
</div>
<?
https://www.jlsprockets.com/Hello,
Please tell me, whats the code about?
- You must be logged in to reply to this topic.