Canceling Appointment on Front-end

When a client is viewing their appointments on the front-end via the [app_my_appointments] shortcode, they have an option to click a check box to cancel an appointment if they choose. When they click that check box a pop-up message opens asking them if they are sure they want to cancel. If the client clicks "OK" to confirm the cancel the pop-up box closes and the appointment is still listed. Not until the client manually refreshed the page does the canceled appointment disappear from the list.

Is there a way to either automatically refresh the page or redirect the client to another page after they click "OK" in the pop-up message?

Thanks

  • Ash
    • WordPress Hacker

    Hello @STEVE

    I hope you are well today and thanks for asking the question.

    Please use the following code:

    add_filter( 'app_footer_scripts', 'app_footer_scripts_cb' );
    function app_footer_scripts_cb( $script ){
    	$sc = 'cancel_box.attr("disabled",true);
    		window.location.href = YOUR URL HERE";
    	';
    	return str_replace( 'cancel_box.attr("disabled",true);', $sc, $script );
    }

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

  • STEVE
    • Site Builder, Child of Zeus

    Thanks for this. I added the code to my child theme's functions.php file, but now the Cancel check box is not working at all. When I tried to click the check box to cancel the appointment, nothing happens. Just a check in a box. Please advise. Support Access is granted in case you wanted to log in and have a look.

    Thanks

  • Ash
    • WordPress Hacker

    Hello @STEVE

    Would you please try this code:

    add_filter( 'app_footer_scripts', 'app_footer_scripts_cb' );
    function app_footer_scripts_cb( $script ){
    	$sc = 'cancel_box.attr("disabled",true);
    		window.location.href = "YOUR URL HERE";
    	';
    	return str_replace( 'cancel_box.attr("disabled",true);', $sc, $script );
    }

    If it still doesn't work, please send me a link where I can see cancel checkbox.

    Cheers
    Ash

  • STEVE
    • Site Builder, Child of Zeus

    It worked this time. But I have a question. Something new and unexpected happened. After I clicked the check box to cancel and before the page was redirected, I was presented with a new popup message I had not seen before. This second popup message said that the appointment was successfully canceled and had an "OK" button. After I clicked that "OK" button, then I was redirected to my chosen page.

    I like this second popup message confirming the appointment was canceled. Is it possible to just refresh the page after clicking the "OK" in the second popup message and not redirect to another page?

    Thanks

  • Ash
    • WordPress Hacker

    Hello @STEVE

    Please this code instead of above:

    add_filter( 'app_footer_scripts', 'app_footer_scripts_cb' );
    function app_footer_scripts_cb( $script ){
    	$sc = 'cancel_box.attr("disabled",true);
    		location.reload();
    	';
    	return str_replace( 'cancel_box.attr("disabled",true);', $sc, $script );
    }

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.