Redirect automatically from Woocommerce thankyou to an external link passing variables

11
March 16, 2019, at 01:50 AM

In Woocommerce, after placing an order, I Would like to redirect customer automatically after 5 sec from the thankyou page to external link passing a few variables as the order_id, and the order_ammount.

So How can I redirect customer automatically from Woocommerce thankyou to an external link passing variables after 5 seconds?

Any track is welcome.

Answer 1

The following code will redirect from checkout page to an external link passing few variables after 5 seconds using php and javascript:

 add_action( 'woocommerce_thankyou', 'thankyou_delated_external_redirection', 10, 1 );
function thankyou_delated_external_redirection( $order_id ){
    if( ! $order_id ){
        return;
    }
    $order          = wc_get_order( $order_id ); // Instannce of the WC_Order Object
    $order_total    = $order->get_total(); // Order total amount
    $link_redirect  = 'http://www.example.com/'; // Base url
    $link_redirect .= ?order_id='.$order_id.'&order_ammount='.$order_total; // passed variables
    ?>
    <script>
    jQuery(function($){
        // Redirect with a delay of 5 seconds
        setTimeout(function(){
            window.location.href = '<?php echo $link_redirect; ?>';
        }, 5000);
    });
    </script>
    <?php;
}

Code goes in function.php file of your active child theme (or active theme). tested and works.

The redirection link is like http://example.com/path/?order_id=1420&order_ammount=136.20

READ ALSO
what is the best database management systeme to use for large chat website? [on hold]

what is the best database management systeme to use for large chat website? [on hold]

actually i ma sedigning a new database for a quite large chat website with some friends, but we think that phpmyadmin isn't that good for, so i need to what DBMS is the best for that, for example what facebook database uses?

17
PHP - Iterate through file and break out chunks of text for JSON

PHP - Iterate through file and break out chunks of text for JSON

I have a file on a server that I need to parse and build a JSON object to returnI am using PHP

47
PHP - How to Change Results from While Loop if Any Row Result Matches

PHP - How to Change Results from While Loop if Any Row Result Matches

I've looked for the result for this, and can't seem to find anything dealing with this specific issue

24
Apache2 + PHP-FPM - undefined function apache_getenv()

Apache2 + PHP-FPM - undefined function apache_getenv()

I have a big problem because for several hours I am trying to run a project that uses SetENV in PHPWhen he even tries to use a simple function apache_getenv();

37