I made a thank you page to redirect clients after

Hello,
I made a thank you page to redirect clients after scheduling a non-payment appointment.
When I add the suggested code to my functions.php file then I get a broken site. I replaced the URL with my confirmation page URL.
function app_redirect( $script ){
return str_replace("window.location.href=app_location()", "window.location.target='_blank' href='http://example.com'", $script);
}
add_filter( 'app_footer_scripts', 'app_redirect' );

Is this code out of date or is something else going on?
Thank you.

  • Emily Journey
    • Flash Drive

    My functions.php file looks like this so I placed the code in a new custom-functions.php
    file with the opening and closing tags.

    <?php
    /***************************************************************************
    *
    * ----------------------------------------------------------------------
    * DO NOT EDIT THIS FILE
    * ----------------------------------------------------------------------
    *
    * Copyright (C) Themify
    * http://themify.me
    *
    ***************************************************************************/

    $theme_includes = apply_filters( 'themify_theme_includes',
    array( 'themify/themify-database.php',
    'themify/class-themify-config.php',
    'themify/themify-utils.php',
    'themify/themify-config.php',
    'themify/themify-modules.php',
    'theme-options.php',
    'theme-modules.php',
    'theme-functions.php',
    'custom-modules.php',
    'custom-functions.php',
    'theme-class.php',
    'themify/themify-widgets.php' ));

    foreach ( $theme_includes as $include ) { locate_template( $include, true ); }

    /**********************************************************************************************************
    *
    * Do not edit this file.
    * To add custom PHP functions to the theme, create a new 'custom-functions.php' file in the theme folder.
    *
    ***********************************************************************************************************/
    ?>

  • Emily Journey
    • Flash Drive

    Yay! I figured it out. I was copy/pasting the code directly from the forum. That was creating a problem. I needed to past it in plain text because something else was getting added into the mix that I couldn't see.
    Now, I just need to figure out how to keep clients from being redirected to the confirmation page when they are canceling an appointment.

  • Patrick
    • Support Monkey

    Hi again @Emily

    Hmm... I just tested that bit of code in functions.php in Twenty-Twelve theme and was correctly redirected to my Thank-You page when scheduling a free appointment.

    However, when I cancel the appointment, I was not redirected. I was cancelling from the My Appointments area on the front-end though, and remained there after cancellation.

    How have you tested with cancellation?

  • Patrick
    • Support Monkey

    @Emily

    Aha! Yes, I get that too when canceling from the confirmation box.

    Right, the script needs to hook somehow into the that button action, rather than hooking into the function that outputs both buttons.

    I'll flag the developer on this topic so gets alerted to this, and can drop by to provide some insight.

    This may take a bit longer than a normal ticket as many members of the team are just now getting back from the staff meetup in NYC, and will likely need some time to catch up: https://premium.wpmudev.org/forums/topic/the-nyc-incsubwpmu-dev-meetup

  • Vladislav
    • Dead Eye Dev

    Hello,

    The str_replace approach will replace all the redirections with the ones that lead to your custom page (example.com in the example). We can remedy this by adding one more filter that will kick in after this and rebind the cancel button specifically back to the previous behavior, like this:

    function rebind_footer_redirections ($script) {
    	return $script . '$(".appointments-confirmation-cancel-button").off("click").on("click", function () {window.location.href=app_location();});';
    }
    add_filter('app_footer_scripts', 'rebind_footer_redirections', 999);

    Please, note that this works in addition to the other bit you already have in place in your functions.php, not instead of it. As I said, the other bit will replace all the redirections with your custom ones. This bit will then come in after that, undo the "Cancel" button action and re-bind it back to the default one.

  • Patrick
    • Support Monkey

    @Emily

    I just tested the snippet added above and it works like a charm on my test site. Can you please add it to your functions.php file and report back?

    Thanks!

    @Vladislav

    Thanks!

    May be good to include that bit in the plugin FAQ for future update too. :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.