• Resolved travis182

    (@travis182)


    Hi, I like the plugin and have 6 services in the dropdown to choose. I’d like to link to the bookingform from 6 different service pages. But I’d like to have the correct service prefilled in the dropdown depending on the link the visitor clicks.
    Is there a way to prefill the service by a variable in the url for instance?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author codepeople

    (@codepeople)

    Hi,

    The solution depends of the plugin version you are using (may require to pass an additional parameter to the booking form shortcode or to create a custom script for selecting the service). Some coding may be needed. Please indicate the version number you are currently using.

    Thank you for using the plugin!

    Thread Starter travis182

    (@travis182)

    Version 1.3.25

    Plugin Author codepeople

    (@codepeople)

    Hi,

    OK, in that version of the plugin you will need a piece of custom script to apply that selection (selecting service based on a URL parameter).

    For example, if the service parameter is specified in the URL this way:

    /sample-page?service=1

    … then the piece of code is like the following:

    jQuery(document).one("showHideDepEvent", function(){
        (function($) {
            location.queryString = {};
            location.search.substr(1).split("&").forEach(function (pair) {
                if (pair === "") return;
                var parts = pair.split("=");
                location.queryString[parts[0]] = parts[1] &&
                    decodeURIComponent(parts[1].replace(/\+/g, " "));
            });
            if (typeof location.queryString.service != 'undefined')
                $(".ahbfield_service option").eq(parseInt(location.queryString.service)-1).prop("selected", true).change();
        })(jQuery); 
    });

    You can paste that piece of code into the settings area “Appointment Hour Booking >> General Settings >> Edit Scripts”.

    Thank you for using the plugin!

    • This reply was modified 3 years, 4 months ago by codepeople.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Prefill service dropdown by url variable’ is closed to new replies.