Appointments+ Calendar on Buddypress profile pages

I'm building a site that is designed to connect local students with tutors, and using Buddypress with A+. Each tutor has a profile, and is in one or more BP groups depending on the subjects they teach, and sets up a schedule.

I found a similar topic a while back, and tried the suggestions there, and it's only partially working...

https://premium.wpmudev.org/forums/topic/schedule-calendar-on-the-buddypress-user-profile-page

An "appointments" tab is visible, but only when looking at one's own profile, which is great, as the tutor can manage their schedule.

What I'm hoping to achieve is having the calendar/schedule of a particular provider be visible to all visitors when they are on that providers profile page.

Preferably, this calendar would be below the base information, but in a "Schedule" tab would be fine too.

Here's the code I have added...

In functions.php...

function my_setup_nav() {
	global $appointments, $bp;
	$a = $appointments;
	if ( !is_object($a) || !$a->is_worker( bp_displayed_user_id() ) )
		return;

	bp_core_new_subnav_item( array(
		'name' => __( 'My Schedule', 'appointments' ),
		'slug' => 'my-schedule',
		'parent_url' => $bp->displayed_user->domain . 'appointments/',
		'parent_slug' => 'appointments',
		'screen_function' => 'tab_template_app_schedule'
	) );
}

function tab_template_app_schedule() {
	add_action( 'bp_template_content', 'screen_content_app_schedule' );
	bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );

}
function screen_content_app_schedule(){
echo do_shortcode( '[app_schedule worker="'.bp_displayed_user_id().'" logged=" " title="My Schedule from START to END"]' );
echo do_shortcode( '[app_pagination]' );
}

add_action( 'bp_setup_nav', 'my_setup_nav', 25 );

and in the footer.php...

<?php function add_app_scripts( $script ){
global $appointments;
$appointments->load_scripts_styles( );
return $script . $appointments->script;
}
add_filter( 'app_bp_footer_scripts', 'add_app_scripts' );?>

Thanks.

  • Adam Czajczyk

    Hello David,

    I hope you're well today and thank you for your question!

    I'm not sure if I'm getting this right.
    I understand that the issue here is that one has to be a "service provider" to be able to see that calendar currently and you would like it be visible for everyone looking at the page.

    Is that correct or am I missing anything here? Could you please provide me with a simple example case scenario? I'll then check the code on my site and try to modify it to meet scenario's criteria.

    Best regards,
    Adam

  • David

    I understand that the issue here is that one has to be a "service provider" to be able to see that calendar currently and you would like it be visible for everyone looking at the page.

    That is correct.

    The way I have this set up is that users who are manually approved to be service providers are added to the appropriate group (subject), then added as a service provider (tutor).

    I would like it so that any user can see that service provider's availability when they go to the profile page.

    Thanks for responding.

  • Milan

    Hey David

    Hope you are well today and thanks for asking us. :slight_smile:

    I want to check which roles you are playing with so that I can try similar solution on my end too. But for that I'll need staff access to your site. So would you please grant us support staff access so that we can check in depth regarding your issue ?. You can grant us support access via WPMU DEV > Support > Support Access > Grant Access. Take a look at this screenshot for easier navigation.

    Look forward to hearing back.
    Cheers,
    Milan

  • Adam Czajczyk

    Hello David!

    I tested your code on my own setup and I think the issue here is not the visibility of a calendar itself but the tab/link availability in BP profile. You can copy a full URL of service providers BP "My Schedule" calendar and access it as a different user (actually every registered user) and it shows the calendar but if you browse user profile (other account that the one you're logged in) the "My Schedule" tab is not available.

    Changing this would require changing Appointments+ core code as "My Schedule" tab is a child-tab (sub-nav item) of "Appointments" tab which is visible only to the "own profile" of a logged in member. There's however a workaround: we can move "My Schedule" to be a part of main profile navigation and set it to be visible for everyone. This seems to be working fine on my test site and allows every registered user to browser service providers' calendars with no restrictions.

    To apply this workaround to your site please replace (in "functions.php" file) this code:

    bp_core_new_subnav_item( array(
    		'name' => __( 'My Schedule', 'appointments' ),
    		'slug' => 'my-schedule',
    		'parent_url' => $bp->displayed_user->domain . 'appointments/',
    		'parent_slug' => 'appointments',
    		'screen_function' => 'tab_template_app_schedule'
    	) );

    with this one:

    bp_core_new_nav_item(
    		array(
    			'name' => __( 'My Schedule', 'appointments'),
    			'slug' => 'my-schedule',
    			'position' => 100,
    			'show_for_displayed_user' => true,
    			'screen_function' => 'tab_template_app_schedule',
    			'default_subnav_slug' => 'my-schedule'
    		)
    	);

    After this change is made you should be able to browser calendars of all service providers.

    Let me know if this helped, please!

    Best regards,
    Adam

  • Adam Czajczyk

    Hello David!

    I'm glad I could help :slight_smile:

    As for booking/interaction. The original code with which we started here didn't include that option either as it wasn't supposed to allow this. It was only a calendar showing availability.

    Luckily, the fix is easy and all is needed here is an additional shortcode. That said, in the code in your "functions.php" file please replace this line:

    echo do_shortcode( '[app_pagination]' );

    with this one

    echo do_shortcode( '[app_pagination]' );
    echo do_shortcode( '[app_confirmation]' );

    I tested it on my site and it's working as expected. The only downside is that after user click on "confirmation" button the page will need to be reloaded to see (I'm referring to display only here) that the booked slot is no longer available.

    Give it a try please and let me know if it worked for you!

    Best regards,
    Adam

    • David

      Hi Adam,

      So I've spent a bit of time playing with the shortcodes, and I might be missing something, but it's close.

      Each service provider has two services attached to them (teaching in studio and teaching in student's home). When someone tries to book a lesson, even if they switch from "in student's home" to the fixed location, the lesson books as "in student's home".

      I figured that I'm missing something in passing variables using shortcodes, but I'm not sure where it's wrong.

      Ideally a user would pick between "in home" or "in studio" once they choose a time, and the right option would be passed through to the confirmation stage.

  • Adam Czajczyk

    Hello David!

    I apologize for such a long delay. It seems that although Milan did notify me about your response, I somehow missed that notification. I'm back "on track" though :slight_smile:

    As for the issue. So far I tested this code with only a single service being assigned to the service provider. You mentioned that the same service is booked even if customer switched to another one. That would mean that you already added service selection shortcode which was not in an original PHP code, is that right?

    On my end I changed this part of the code:

    function screen_content_app_schedule(){
    echo do_shortcode( '[app_schedule worker="'.bp_displayed_user_id().'" logged=" " title="My Schedule from START to END"]' );
    echo do_shortcode( '[app_pagination]' );
    echo do_shortcode( '[app_confirmation]' );
    }

    to this one

    function screen_content_app_schedule(){
    echo do_shortcode( '[app_services worker="'.bp_displayed_user_id().'"]' );
    echo do_shortcode( '[app_schedule worker="'.bp_displayed_user_id().'" logged=" " title="My Schedule from START to END"]' );
    echo do_shortcode( '[app_pagination]' );
    echo do_shortcode( '[app_confirmation]' );
    }

    As you can see, there's a service selection shortcode added at the top and it's "tied" to the current (viewed) service provider. This is working fine on my test setup but only if after selecting service I also click on a "Show avialable times" button. Only then the schedule table is reloaded and selected service is assigned. Otherwise it does indeed book the "original" service.

    Therefore, there's one more "tweak" needed. The first line of function's code (the one with service selection shortcode) should include "autorefresh" attribute:

    echo do_shortcode( '[app_services worker="'.bp_displayed_user_id().'" autorefresh="1"]' );

    As a result, the "Show available times" button will not be displayed and the booking schedule table should be automatically reloaded after user selects service from the drop-down list. On my test setup this works well. Could you please give it a try and let me know if it works for you?

    In case it still didn't work, please switch your site temporarily to Twenty Fifteen or Twenty Sixteen WP theme, make sure that you cleared all caches and give it another try.

    Best regards,
    Adam

  • David

    Thanks for all the help. Everything is working as expected!

    There's only one other question... I've searched support, and I see that A+ doesn't support coupon codes. We have Marketpress installed, and when a user books a time via the MP product page, the coupon code works.

    The option to enter a code doesn't appear when booking on a profile page. I've seen the topic come up before, with no real resolution.

    Is it possible to redirect the user at the [app_confirmation] point to a MP product page with the pertinent variables filled in, or some other way to inject a MP coupon code on the page?

    I'm not sure if I should be asking in this thread, or start a new support question with MarketPress tagged, as I realize it's going afield from the original topic.

  • Milan

    Hello David

    Hope you are well today and won't mind me chiming in. :slight_smile:

    I'm not sure if I should be asking in this thread, or start a new support question with MarketPress tagged, as I realize it's going afield from the original topic.

    You are absolutely right. This thread is intended to target your issue with Appointments+ and BuddyPress profile tab. Your new question is quite different in context of associate plugins. So I suggest you to create new thread for this. :slight_smile:

    Hope you will find this useful. :slight_smile:
    Kind Regards,
    Milan

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.