Load service by default

In the book appointment page, I want a service to load by default. So an option to choose a default service for [app_services] would be great.

In addition, is there any way to select multiple services in [app_monthly_schedule] shortcode, like [app_monthly_schedule service="2,4,6"]?

And lastly, in [app_services] shortcode can we just select some services? I mean, adding service as a new shortcode attribute?

  • Adam Czajczyk

    Hello Ashwin,

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

    In the book appointment page, I want a service to load by default. So an option to choose a default service for [app_services] would be great.

    As of now, the "default" service is always the one that's "on top of the select list". Which one that is depends on what "Order By" option you select in shortcode generator. The default option for that is "ID" so the "default" service would be the one with the lowest ID.

    While there's currently no way to explicitly select a default service, you could actually use a small "trick":

    - when you generate a shortcode make sure that "order by" is set to "ID"
    - go to "Appointments -> Settings -> Services"
    - edit your services (or remove them and add again) in that way that the one you want to be default one, would be the first on the list (so it would have the lowest ID - you see it in the very first column of the list there).

    In addition, is there any way to select multiple services in [app_monthly_schedule] shortcode, like [app_monthly_schedule service="2,4,6"]?

    This shortcode displays booking calendar which lets you book a given service. It cannot display more than one service because it would mean booking two services at once which wouldn't work. Services might be of different duration, from different service providers etc so that'd lead to a lot of conflicts and issues. The way is to either multiply the shortcode with a different service in each or to use no service attribute and use service selection drop-down.

    If I misunderstood the goal here or am missing the way it should work, please correct me.

    And lastly, in [app_services] shortcode can we just select some services? I mean, adding service as a new shortcode attribute?

    There's no option to do it currently but I created a little code snippet for you to overcome this for now:

    <?php 
    
    function app_only_selected_services_services_shortcode($services) {
    
    	$selected_services = array('2','4'); // list your selected services ID's here as array values
    
    	$new_services = array();
    	foreach ( $services as $service ) {
    		if ( in_array( $service->ID, $selected_services ) ) {
    			array_push( $new_services, $service);
    		}
    	}
    
    	return $new_services;
    
    }
    add_filter('app_services', 'app_only_selected_services_services_shortcode', 10, 1);

    To apply it on your site:

    1. Create an empty file with .php extension (for example: "appointments_service_shortcode_limit.php") and copy and paste code from above to that file.

    2 . In this line

    $selected_services = array('2','4'); // list your selected services ID's here as array values

    define your services by IDs. You will find service IDs on "Appointments -> Settings -> Services" page in the very first column of the list. Simply follow the convention to specify them (numbers inside single quotes, separated by commas)

    Make sure that you're editing the code with a "clean text" editor (such as e.g. Notepad++, Sublime or similar).

    3. Access your server via FTP or cPanel "File Manager" and upload that file to the "/wp-content/mu-plugins" folder; if there's no "mu-plugins" folder inside the "/wp-content" folder, create it there.

    That's pretty much it, the code should work out of the box.

    That being said, those issues had already also been reported to our developers so please keep an aye on this thread for more information.

    Best regards,
    Adam

  • Ashwin

    Hi Adam,

    I think maybe what I need didn't come across correctly.

    So my client does 2 main things. Fitness training and tennis lessons. There are multiple options for each in terms of classes.

    I have 2 pages on his site for the 2 different types of services. So I need the user to be able to select the service. But it is odd that on the tennis page, the default (on top of the list) is fitness. Even if i fix that, the other page will be wrong. So the solutions that i came up with were to either specify in the short code, what list item should show as default in that instance OR give a comma separated group of services that the list would display. So that is what I am asking about. I will try this code that you have given and see if it will solve the issue.

  • Predrag Dubajic

    Hi Ashwin,

    Mind if I jump in :slight_smile:

    I was checking your chat and it seems that you didn't try order_by attribute in the shortcode, and you can use this to sort the dropdown items.

    For example, it can look like this:
    [app_services order_by="ID ASC"]
    This will sort it by ID in Ascending order.
    Instead of ID you can also use name to sort by name, and instead of ASC you can also use DESC to sort in Descending order.

    So one page can have [app_services order_by="ID ASC"] and other [app_services order_by="ID DESC"] and that should do the trick.

    Let us know if that will do it for you.

    Best regards,
    Predrag

  • Ari

    Hey Ashwin

    Hope you are fine today!

    I understood the problem, I made a fix by mu-plugin for you, this works fine from my end. To activate it please follow the below steps:

    === Solution ===
    1: Download the mu-plugin as zip from this gist: https://gist.github.com/wpmudev-sls/88ce46b3fb45086d4f4522d5289d5387
    2: Create mu-plugins folder inside the wp-content folder by FTP or cPanel.
    3: Upzip the gist file, upload the appointments_default_service.php to the mu-plugins folder.

    This file will activate the functionality to add default param to the app_services shortcode. So you can use it like:

    [app_services default="2"]

    Here's the screenshot:

    === What is mu-plugins? ===
    mu-plugins also called "must use plugins" is auto-activated plugin, that's mean by adding that file inside the "mu-plugins" the code is automatically start functioning without any activation from dashboard.
    If you need to more about mu-plugins, here's the link: https://codex.wordpress.org/Must_Use_Plugins
    In future if you need to deactivate it, just remove this file.

    Please let me know is this fix works fine from your end or if you have any trouble regarding this issue. Have a great day!

    Cheers,
    Ari

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.