Configuring all_appointments view

Is there a way to configure the [app_all_appointments] view to change the columns that are displayed? Specifically, I'd like to be able to show each of the fields that the user inputs.

  • Vaughan

    Hi @augusto,

    Welcome to the forum.

    It could possibly be done, which fields are you wanting to display exactly?

    You would first need to add the columns to the table, you can use a filter for this in your theme functions.php

    Then add the filters for your new columns

    function add_app_columns() {
        $columns = '<th class="all-appointments-service">'. __('Service', 'appointments' )	. '</th>
                            <th class="all-appointments-provider">' . __('Provider', 'appointments' ) . '</th>
                            <th class="all-appointments-client">' . __('Client', 'appointments' )  . '</th>
                            <th class="all-appointments-date">' . __('Date/time', 'appointments' )  . '</th>
                            <th class="all-appointments-status">' . __('Status', 'appointments' ) . '</th>
                            <th class="all-appointments-newfield1">New Field 1</th>
                            <th class="all-appointments-newfield1">New Field 1</th>
                            ';
        return $columns;
    }
    add_filter( 'app_all_appointments_column_name', 'add_app_columns', 999);
    
    function add_app_cell() {
        $cells = '<td>New Field 1 code here'</td>
                      <td>New Field 2 code here</td>
                      ';
        return $cells;
    }
    add_filter( 'app_all_appointments_add_cell', 'add_app_cell', 999);

    However, i'm not sure exactly of the code you would use to display the inputted details, such as the custom fields or address etc, so I will ask one of our developers for some further assistance with this.

    If you could let us know exactly what data you want added, it would help.

    Hope this helps

  • Hoang Ngo

    Hi @Augusto,

    I hope you are well today

    Please add this code to your theme functions.php or use mu-plugins

    add_filter( 'app_all_appointments_after_table', 'custom_all_app_table', 10, 2 );
    function custom_all_app_table( $html, $results ) {
    	global $appointments;
    
    	$ret = '';
    	$ret .= '<div class="appointments-all-appointments">';
    	$ret .= $title;
    	$ret = apply_filters( 'app_all_appointments_before_table', $ret );
    	$ret .= '<table class="all-appointments tablesorter"><thead>';
    	$ret .= apply_filters( 'app_all_appointments_column_name',
    		'<th class="all-appointments-email">' . __( 'Email', 'appointments' )
    		. '</th><th class="all-appointments-phone">' . __( 'Phone', 'appointments' )
    		. '</th><th class="all-appointments-field1">' . __( 'Field 1', 'appointments' )
    		. '</th><th class="all-appointments-field2">' . __( 'Field 2', 'appointments' )
    		. '</th><th class="all-appointments-field3">' . __( 'Field 3', 'appointments' ) . '</th>'
    	);
    
    	$colspan = 5;
    
    	$ret .= '</thead><tbody>';
    
    	if ( $results ) {
    		$data = get_option( 'appointments_data' );
    		foreach ( $results as $r ) {
    			$custom_field = isset( $data[$r->ID] ) ? $$data[$r->ID] : array();
    			$ret .= '<tr><td>';
    			$ret .= $r->email . '</td>';
    			$ret .= apply_filters( 'app-shortcode-all_appointments-after_service', '', $r );
    
    			$ret .= '<td>';
    			$ret .= $r->phone . '</td>';
    			$ret .= apply_filters( 'app-shortcode-all_appointments-after_provider', '', $r );
    
    			$ret .= '<td>';
    			$ret .= isset( $custom_field['field1_id'] ) ? isset( $custom_field['field1_id'] ) : null . '</td>';
    			$ret .= apply_filters( 'app-shortcode-all_appointments-after_client', '', $r );
    
    			$ret .= '<td>';
    			$ret .= isset( $custom_field['field1_id'] ) ? isset( $custom_field['field1_id'] ) : null . '</td>';
    			$ret .= apply_filters( 'app-shortcode-all_appointments-after_date', '', $r );
    
    			$ret .= '<td>';
    			$ret .= isset( $custom_field['field1_id'] ) ? isset( $custom_field['field1_id'] ) : null;
    			$ret .= '</td>';
    			$ret .= apply_filters( 'app-shortcode-all_appointments-after_status', '', $r );
    
    			$ret .= apply_filters( 'app_all_appointments_add_cell', '', $r );
    			$ret .= '</tr>';
    		}
    	} else {
    		$ret .= '<tr><td colspan="' . $colspan . '">' . __( 'No appointments', 'appointments' ) . '</td></tr>';
    	}
    	$ret .= '</tbody></table>';
    
    	return $ret;
    }

    Also, you will need to modify the custom field ID, example you add a field called test, so the field_id will be test

    If you have any issues please don't hesitate to let us know so we can assist

    Best regards,
    Hoang

  • Augusto

    Hi there,

    It's starting to work now. I should have clarified that I'd like to keep the Client and Date/Time fields, adding these 5 have overwritten all the others. What code do I need to put in to get that data back?

    Also, I'm having trouble displaying the custom fields. For reference, here are the names:

    Current Employer:
    Current Job Title:
    General Area of Question:

    But I can't seem to get them to show up, replacing both of the 'field1_id' with 'currentemployer', 'current_employer', 'current%20employer', and other variations. Is the space and the colon throwing off the field_id?

  • Vaughan

    Hi @augusto,

    I've reworked the code a bit that @Hoang Ngo provided.

    This should work fine now, you still need to replace the field1_id etc with your own fields.

    add_filter( 'app_all_appointments_after_table', 'custom_all_app_table', 10, 2 );
    function custom_all_app_table( $html, $results ) {
    	global $appointments;
    
    	$ret = '';
    	$ret .= '<div class="appointments-all-appointments">';
    	$ret .= $title;
    	$ret = apply_filters( 'app_all_appointments_before_table', $ret );
    	$ret .= '<table class="all-appointments tablesorter"><thead>';
    	$ret .= apply_filters( 'app_all_appointments_column_name',
                            '<th class="all-appointments-service">' . __('Service', 'appointments' ) . '</th>
                            <th class="all-appointments-provider">' . __('Provider', 'appointments' ) . '</th>
                            <th class="all-appointments-client">' . __('Client', 'appointments' )  . '</th>
                            <th class="all-appointments-date">' . __('Date/time', 'appointments' )  . '</th>
                            <th class="all-appointments-status">' . __('Status', 'appointments' ) . '</th>
                            <th class="all-appointments-email">' . __( 'Email', 'appointments' ) . '</th>
                            <th class="all-appointments-phone">' . __( 'Phone', 'appointments' ) . '</th>
                            <th class="all-appointments-field1">' . __( 'Field 1', 'appointments' )	. '</th>
                            <th class="all-appointments-field2">' . __( 'Field 2', 'appointments' )	. '</th>
                            <th class="all-appointments-field3">' . __( 'Field 3', 'appointments' ) . '</th>'
    	);
    
    	$colspan = 5;
    
    	$ret .= '</thead><tbody>';
    
    	if ( $results ) {
    		$data = get_option( 'appointments_data' );
    		foreach ( $results as $r ) {
    			$custom_field = isset( $data[$r->ID] ) ? $data[$r->ID] : array();
    				$ret .= '<tr><td>';
    				$ret .= $appointments->get_service_name( $r->service ) . '</td>';
    				$ret .= apply_filters('app-shortcode-all_appointments-after_service', '', $r);
    
    				$ret .= '<td>';
    				$ret .= $appointments->get_worker_name( $r->worker ) . '</td>';
    				$ret .= apply_filters('app-shortcode-all_appointments-after_provider', '', $r);
    
    				$ret .= '<td>';
    				$ret .= $appointments->get_client_name( $r->ID ) . '</td>';
    				$ret .= apply_filters('app-shortcode-all_appointments-after_client', '', $r);
    
    				$ret .= '<td>';
    				$ret .= date_i18n( $appointments->datetime_format, strtotime( $r->start ) ) . '</td>';
    				$ret .= apply_filters('app-shortcode-all_appointments-after_date', '', $r);
    
    				$ret .= '<td>';
    				$ret .= App_Template::get_status_name($r->status) . '</td>';
    				$ret .= apply_filters('app-shortcode-all_appointments-after_status', '', $r);
    
                $ret .= '<td>';
    			$ret .= $r->email . '</td>';
    			//$ret .= apply_filters( 'app-shortcode-all_appointments-after_service', '', $r );
    
    			$ret .= '<td>';
    			$ret .= $r->phone . '</td>';
    			//$ret .= apply_filters( 'app-shortcode-all_appointments-after_provider', '', $r );
    
    			$ret .= '<td>';
    			$ret .= isset( $custom_field['field1_id'] ) ? $custom_field['field1_id'] : null . '</td>';
    			$ret .= apply_filters( 'app-shortcode-all_appointments-after_client', '', $r );
    
    			$ret .= '<td>';
    			$ret .= isset( $custom_field['field2_id'] ) ? $custom_field['field2_id'] : null . '</td>';
    			$ret .= apply_filters( 'app-shortcode-all_appointments-after_date', '', $r );
    
    			$ret .= '<td>';
    			$ret .= isset( $custom_field['field3_id'] ) ? $custom_field['field3_id'] : null;
    			$ret .= '</td>';
    			$ret .= apply_filters( 'app-shortcode-all_appointments-after_status', '', $r );
    
    			$ret .= apply_filters( 'app_all_appointments_add_cell', '', $r );
    			$ret .= '</tr>';
    		}
    	} else {
    		$ret .= '<tr><td colspan="' . $colspan . '">' . __( 'No appointments', 'appointments' ) . '</td></tr>';
    	}
    	$ret .= '</tbody></table>';
    
    	return $ret;
    }

    Hope this helps

  • Augusto

    Great! Now the report's showing all the data I want it to.

    Just one last thing relating to formatting, as you can see from the attached image, the first 5 columns get plenty of space, but the last two are getting squeezed a lot, in both Firefox and IE. Chrome gives them a bit more room, but it's still pretty tight.

    Is there a way to adjust the widths of the columns from this code? Or is this something I have to mess around with my theme's CSS in order to get right?

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.