Appointments: Additional fields based on the Service

A few questions.
Is it possible to display additional fields based on the selected service?
Is it possible to remove some of the default fields?
Is it possible to pass some of the info from the booking confirmation being completed to the confirmation page?

  • Adam Czajczyk

    Hello Federico,

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

    Currently the Appointments+ plugin doesn't support these features out of the box. All of these goals could be achieved with some custom coding though. A custom development would however be a bit outside of the scope of this forum so if you feel like giving that coding a try by yourself, please feel free to ask any questions and I'll do my best to give you some handy tips and advice on this.

    If you however need it to be created for you as a ready to use code, you may want to post a question on our "Jobs & Pros" job board (please note: no WPMU DEV staff involved!) here:

    https://premium.wpmudev.org/wordpress-development/

    Kind regards,
    Adam

  • 3818

    Ok what i did is just remove them from the shortcode.

    for displaying the fields i did the following.

    I hid them by default in css and then used the following javascript to display them when needed.

    var dropdown = document.getElementById("app_select_services");
            var selectedText = dropdown.options[dropdown.selectedIndex].text;
            if (selectedText.includes("Drug Screen")) {
                document.getElementsByClassName('appointments-customfield1-field')[0].style.visibility = 'visible';
                document.getElementsByClassName('appointments-customfield2-field')[0].style.visibility = 'visible';
            }

    For passing info to the thankyou page i did the following.

    var url = window.location.href;
            var arr = url.split("/");
            result = arr[0] + "//" + arr[2];
            result = result.replace(/^https?\:\/\//i, "");
            var dropdown = document.getElementById("app_select_services");
    var element = document.querySelector('.appointments-confirmation-button');
            element.addEventListener("click", function (e) {
                var service_name = $('.appointments-confirmation-service').text();
                var service_provider = $('.appointments-confirmation-worker').text();
                var appointment = $('.appointments-confirmation-start').text();
                var location = $('.app_service_excerpt:visible').children(":first").text();
                location = trim1(location);
                eraseCookie("service_name");
                eraseCookie("service_provider");
                eraseCookie("appointment");
                eraseCookie("location");
                createCookie("service_name", service_name, 30);
                createCookie("service_provider", service_provider, 30);
                createCookie("appointment", appointment, 30);
                createCookie("location", location, 30);
    
            }, false);
    
    function createCookie(name, value, days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            var expires = "; expires=" + date.toUTCString();
        }
        else var expires = "";
        domainname = getDomainName
        document.cookie = name + "=" + value + expires + "; path=/; domain=." + result;
    }
    function eraseCookie(name) {
        createCookie(name, "", -1);
    }
    function getDomainName(hostName) {
        return hostName.substring(hostName.lastIndexOf(".", hostName.lastIndexOf(".") - 1) + 1);
    }
    function trim1 (str) {
        return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    }

    Basically i make sure the cookies are being set for the site domain, erasing them first to make sure they don't exist and then creating them.

    Then in a custom page

    $service_name=  $_COOKIE["service_name"];
        $service_provider=  $_COOKIE["service_provider"];
        $appointment=  $_COOKIE["appointment"];
        $location=  $_COOKIE["location"];

    i pull the cookies and display them.

    Hopefully this can help someone in the future.

  • Adam Czajczyk

    Hello Federico!

    The confirmation alert script is generated by the "/includes/shortcodes/js/app-confirmation.js" file and the file is loaded (and I think executed too) by the "/includes/shortcodes/class-app-shortcode-confirmation.php" file within the "process_shortcode()" function that starts around line no. 87.

    I think the relevant code would start around the 221 line in that file.

    Best regards,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.