[Appointments+] I want to allow users to add services and become provider

Current Appoitment+ integration with BuddyPress don't allow us to become the service provider from the frontend and not even allow us to add services. Please help

  • Ash

    Hello Komal

    Yes, currently the plugin can be configured by admins only. Thank you for your suggestion. I am marking this as a feature request for now, let's see how other members think about this.

    Though, if you have a multisite, and make site registration open, then every user can create a subsite and can configure their own system. You can use New Blog Templates to give them a ready-made template site when they register.

    Have a nice day!


  • Komal

    Hello Ash,

    I am little bit confused with a Method declaration, like i am not able to find the location where it is exactly execute.
    private function _save_workers()
    Because i think
    _add_worker() is used to add the Worker
    _update_worker() is used to update the worker with new values.

    This is the Case defined in this file:
    case 'save_workers': {

    But the _save_worker() is not used any where, so i think its extra method which is declared. Can you please help me?


  • Panos

    Hi Komal ,

    To answer your question, that is where _save_worker is used. It is called when the action_app is add_new_worker.

    Regarding your requirement, there are many ways to implement it with some custom coding. We can't provide the exact solution for this as this is really custom code and exceeds the scope of the support forum, but I have prepared a snippet which you can use as a guide. You can download file from here :
    and upload it to your wp-content/mu-plugins folders.

    After adding this, each user that is not a provider, will be able to see a list of services to choose from, in the Appointments page in BuddyPress menus (site.com/members/USER_NAME/appointments/)

    You can use this snippet as a guide and modify so it meets your needs :slight_smile:

    Please let us know if something is not clear or if I missed something.


  • Komal

    Thanks For Such a Great Help, But i was having solution already.

    But i have tested the Code and when we add a new worker basically _add_workers() is used and i can confirm using the var_dump statement which i directly added there and tested. Not the _save_workers() is used when we add the worker. And i have tested the code many times.

    And there is new method _update_worker(), which is introduced in 2.3.0 and i think _save_workers() was may be used before for update purpose. But now i think _update_workers() has replaced the _save_workers().

    Is that right? Can you please confirm again?

  • Panos

    Hey Komal ,

    Those functions are both being used in different cases, however I don't think that those are a good fit for adding a new worker by looking at them.

    By _update_workers() you mean the private method _update_worker() (without the "s" ) of the Appointments_Admin_Settings_Page class?

    I don't think that would work as it is a private method, so not accessible outside the class and it uses the appointments_update_worker() which does not insert new worker of what I see.

    Similar for _save_workers(), it's also a private method and it also doesn't use the appointments_insert_worker(), it uses the appointments_update_worker(), so again it doesn't seem to be adding new workers.


  • Komal

    I think i haven't able to explained you properly.

    Basically i was reading the code to better understand the all the cases which may be there when inserting the working and updating the worker.

    But i came across three methods which were there.
    1) Add Worker
    2) Save Worker
    3) Update Worker

    Save is having some two condition if and else

    private function _save_workers() {
    		// Save Workers
    		if ( ! is_array( $_POST['workers'] ) ) {
    		foreach ( $_POST['workers'] as $worker_id => $worker ) {
    			$new_worker_id = absint( $worker['user'] );
    			$worker_id = absint( $worker_id );
    			if ( appointments_is_worker( $worker_id ) ) {
    				// Update
    				if ( ( $new_worker_id != $worker_id ) && ! empty( $worker['services_provided'] ) ) {
    					// We are trying to chage the user ID
    					$count = appointments_get_worker( $new_worker_id );
    					// If the new ID already exist, do nothing
    					if ( ! $count ) {
    						// Otherwise, change the ID
    						$args = array(
    							'ID' => $new_worker_id,
    							'price' => $worker['price'],
    							'services_provided' => $worker['services_provided'],
    							'dummy' => isset( $worker['dummy'] ),
    							'page' => $worker['page'],
    						appointments_update_worker( $worker_id, $args );
    				} elseif ( ( $new_worker_id == $worker_id ) && ! empty( $worker['services_provided'] ) ) {
    					// Do not change user ID but update
    					$args = array(
    						'price' => $worker['price'],
    						'services_provided' => $worker['services_provided'],
    						'dummy' => isset( $worker['dummy'] ),
    						'page' => $worker['page'],
    					appointments_update_worker( $worker_id, $args );
    				} elseif ( empty( $worker['services_provided'] ) ) {
    					appointments_delete_worker( $worker_id );
    				do_action( 'app-workers-worker-updated', $worker_id );

    And as per my tests $_POST['workers'] never exists. So, its never executed as per my test on Add/Update

    So, i just want to know I'm i right or wrong. I am coding my own conditions for my frontend submissions, so its better to consider the base which already exists.
    Did you get what, i just explained?

  • Panos

    Hi Komal ,

    After checking a bit closer the save_workers() is not used as you said. Previously I checked if it was called from anyplace, but I didn't notice that the save_workers action is not used.

    It seems that this function would bulk update cause it expects $_POST['workers'] to be an array. It is not a good example of what you need to follow though.

    I do not know how you have this implemented on your custom code, I would suggest something similar to the snippet I shared https://gist.github.com/wpmudev-sls/f616ea86bb9c784f30ffa6c74a0748cf

    In the add_provider_ajax() method it uses the appointments_insert_worker() which uses some args.

    The main args you need is for user id and the list of services id as you can see at this part:

    $user_id = filter_input( INPUT_POST, 'user_id', FILTER_VALIDATE_INT );
    			$args = array(
    				'ID'				=> $user_id,
    				'price'				=> '',
    				'services_provided'	=> $_POST['app_services_list'],
    				'page'				=> '',
    				'dummy'				=> '',
    			$worker_id = appointments_insert_worker( $args );

    You can confirm this in the Appointments_Admin_Settings_Page::_add_worker() method where it does the same.

    In case you want to update worker from front end I would suggest to follow the _update_worker() as an example. That uses the appointments_update_worker()

    Kind regards!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.