In appointments + can the name of the appointment holder be shown inplace of the shaded time slot

My client would like the name of the appointment holder to show instead of the greyed out time when a time slot is filled. Is this possible?

  • Jose

    Hi @Jeanette,

    Hope you are doing great today!

    I made this custom code for you, wrapped as a must-use plugin.

    You only need to download the attached file and place the file custom-code.php into the folder:
    ../wp-content/mu-plugins/

    Create the folder if it doesn't exists.

    This plugin will hook into the filter 'app-schedule_cell-title', adding the app holder name (or names, in case the capacity allows more than one appointment per time slot) to the title attribute of the DIV tag.

    Then, a jQuery routine will go through the busy cells, grab the names from the title attribute, and use that value to populate the cell.

    Hope this works fine for you. Please let me know if you need help implementing the plugin.

    Cheers!

    This is the code, just for reference:

    if(! class_exists('Custom_Code') ):
    
        class Custom_Code{
    
            function __construct(){
    
                add_filter('app-schedule_cell-title', array($this, 'app_title_filter'), 20, 5);
                add_action('wp_footer', array($this, 'add_javascript'));
            }
    
            function add_javascript(){
                ?>
                <script type="application/javascript">
                    jQuery(document).ready( function(){
                        var cell = jQuery('.app_timetable_cell.busy');
                        var app_holders = cell.attr('title').split('|')[1];
                        cell.html(app_holders);
                    });
                </script>
    
            <?php
            }
    
            function app_title_filter( $title, $is_busy, $ccs, $cce, $schedule_key ){
                if($is_busy){
                    $holders = $this->get_app_holders($ccs, $cce);
                    return $title . " | ".implode(",", $holders);
                }
    
                return $title;
            }
    
            function get_app_holders( $start, $end ) {
                global $appointments;
    
                $holders = array();
                $week= date( "W", $start );
                $period = new App_Period($start, $end);
    
                // If a specific worker is selected, we will look at his schedule first.
                if ( 0 != $appointments->worker ) {
                    $apps = $appointments->get_reserve_apps_by_worker( $appointments->location, $appointments->worker, $week );
                    if ( $apps ) {
                        foreach ( $apps as $app ) {
                            var_dump($app);
                            if ($period->contains($app->start, $app->end)) {
                                $holders[] = $app->name;
                            }
                        }
                    }
                    return $holders;
                }
                if ( $appointments->get_workers() != null ) {
                    $workers = $appointments->get_workers_by_service( $appointments->service );
                    $apps = array();
                    if ( $workers ) {
                        foreach( $workers as $worker ) {
                            if ( $appointments->is_working( $start, $end, $worker->ID ) ) {
                                $app_worker = $appointments->get_reserve_apps_by_worker( $appointments->location, $worker->ID, $week );
                                if ( $app_worker && is_array( $app_worker ) )
                                    $apps = array_merge( $apps, $app_worker );
    
                                // Also include appointments by general staff for services that can be given by this worker
                                $services_provided = $appointments->_explode( $worker->services_provided );
                                if ( $services_provided && is_array( $services_provided ) && !empty( $services_provided ) ) {
                                    foreach ( $services_provided as $service_ID ) {
                                        $apps_service_0 = $appointments->get_reserve_apps( $appointments->location, $service_ID, 0, $week );
                                        if ( $apps_service_0 && is_array( $apps_service_0 ) )
                                            $apps = array_merge( $apps, $apps_service_0 );
                                    }
                                }
                            }
                        }
                        $apps = $appointments->array_unique_object_by_ID( $apps );
                    }
                }
                else
                    $apps = $appointments->get_reserve_apps_by_worker( $appointments->location, 0, $week );
    
                $n = 0;
                foreach ( $apps as $app ) {
                    if ($appointments->worker && $appointments->service && ($app->service != $appointments->service)) {
                        continue;
                    }
                    if ($period->contains($app->start, $app->end)) {
                        var_dump($app);
                        $holders[] = $app->name;
                        $n++;
                    }
                }
                return $holders;
            }
    
        }
        new Custom_Code;
    
    endif;
  • pxwm

    Hi @Jose

    I was interested in using this bespoke plugin to populate the busy time slots in the schedule with another variable from each appointment.

    However I've tried uploading in to the mu-plugin folder and also just uploading as a plugin and activating.

    Using both methods breaks the A+ plugin.

    When the custom plugin is installed:-

    -Our Service and Service Provider shortcodes are set with autorefresh
    -When the A+ page is refreshed it then displays the 'Show Available Time' refresh button
    -If I select a Service and click the button the page is not refreshed.
    -I've tried selecting a date on the schedule and nothing happens.
    -I would suggest there may be a jquery conflict
    -I've deactivated all other plugins except A+ and also activated the Wordpress default theme but no luck

    Any ideas?

    I thought I'd also mention that if you install this bespoke plugin in the plugins folder it indicates there is an update.
    However it would appear someone else has called there plugin the same name

    Regards
    SteveB

  • pxwm

    Hi @Jose

    I haven't identified the problem to date.

    I'm running:-

    - A+ v1.4.4
    - no A+ bespoke code
    - Wordpress v3.9.2
    - no plugins except A+ and your custom plugin installed in mu-plugins folder
    - twenty twelve theme
    - the 'Services' and 'Service Provider' shortcodes have the 'autorefresh' parameter set

    It would be great if you could test to see if you can replicate my problem.

    Regards
    SteveB

  • Jose

    Hey Steve,

    You were right, my code wasn't working pretty well. Actually, it worked fine if there was busy cells in the timetable, otherwise it was throwing a huge error. :slight_smile:

    Now, you can find the "release candidate" version attached. :stuck_out_tongue:

    It is not only tested but also re-factored to use a proper name, with fancy description included.

    Please give it a try and let me know.

    Cheers!
    Jose

  • Jose

    Hey Steve,

    Yeah, this code works only for monthly schedule. Didn't try with weekly schedule, but I guess it would take just a few adjustments to work.
    Would you dare to try and share it here? :wink:

    For the other requirement, I'm not totally clear.
    Do you mean to print the content of the field into the cell?
    When you said "instead of the Service Provider/Worker name" you actually mean instead of the application holder name, right?

    Please advise,

    Cheers,
    Jose

  • pxwm

    Hi @Jose

    That's great, much appreciated.
    I will certainly try this and let you know.

    I hope you don't mind me using this post to ask you one further question:-

    When A+ sends an email notification to the Service Provider I would also like to send the same email notification to another email address at the same time.
    The email address may be owned by another Wordpress user profile or may be just any email address.

    I've found some code by Hoang Ngo in another post: https://premium.wpmudev.org/forums/topic/stop-admin-emails-send-no-service-provider-selected-to-2-emails

    that relates to disabling the admin email and sending out an email notification to a number of Service Providers.

    However I wondered if there was a hook I could use so when the appointment form is submitted and sends an email notification to the Service Provider, it also sends an email notification to one or more other email addresses.

    I would appreciate if you could consider and give me some guidance so I can maybe add some bespoke code to the functions.php etc.

    Many thanks again for all your support

    Regards
    SteveB

    • Jose

      Hey Steve,

      You can make use of 'app_notification_sent' and 'app_confirmation_sent' actions.
      The first one is triggered when a free appointment is created and the status is pending.
      The second one is triggered when an appointment is confirmed.

      You can see the details of each case by diving into the code.
      In the file wp-content/plugins/appointments/appointments.php from line 4327 to line 4472 you will find the definition if the routines send_confirmation() and send_notification().

      The parameters sent with the hook call are the same for both actions:
      - Email body
      - Appointment element. (the row returned from DB)
      - Appointment ID

      The trigger looks like this:
      do_action( 'app_notification_sent', $body, $r, $app_id );

      Let me know how it goes. If you get stuck, please open a new thread so that we can provide you further support.

      Cheers!
      Jose

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.