WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
[resolved] Redirect after checkout in WooCommerce (15 posts)

  1. ThreeBees
    Member
    Posted 1 year ago #

    Hello. I am wondering if anyone knows how to redirect a person after Checkout in WooCommerce to GoToWebinars (or anything else for that matter). I would like to automatically redirect them to a registration page after payment. If anyone has any idea on how I could achieve this it would be much appreciated.

    Cheers.
    3bs

    http://wordpress.org/extend/plugins/woocommerce/

  2. IgniteWoo
    Member
    Posted 1 year ago #

    You could modify the "Thank you" page template to include a simple redirect via javascript. The page is titled "Order Received" by default. The template file itself is in the woocommerce plugin directory unless your theme has a set of checkout page templates.

    Look in your theme directory for this file:

    woocommerce/checkout/thankyou.php

    If it exists, edit that to include a javascript redirect.

    If it doesn't exist, copy it from

    wp-content/plugins/woocommerce/templates/checkout/thankyou.php

    to

    wp-content/themes/YOUR_THEME/woocommerce/checkout/thankyou.php

    Add something like this:

    <script>
    window.location = 'http://redirect-to-this-page'
    </script>
  3. ThreeBees
    Member
    Posted 1 year ago #

    Ok. Thanks. However the redirect will change per product. Is it possible to have it redirect depending on product sold? (different webinar signup page per product)

    It would be great to have a redirect area in the downloads section of Woo :)

    Is there another - easier way I could do this?

    Cheers in advance.

    3bs

  4. simonswiss
    Member
    Posted 1 year ago #

    I am trying to do exactly the same - have a post-product-purchase redirect, maybe adda custom field with an URL that would then be the redirect page, different from product to product..

  5. Spinal
    Member
    Posted 1 year ago #

    +1 for this. Would love to have an option to have a different "thank you" page based on what product is bought.

  6. justradar
    Member
    Posted 1 year ago #

    i'm also very interested in doing this

  7. nazmul40
    Member
    Posted 9 months ago #

    thanks to you http://ignitewoo.com/

  8. Chee Studio
    Member
    Posted 5 months ago #

    After beating on this incessantly, I finally found something that inched me closer to what is being requested here, so I thought I'd post it. In my case, I wanted to customize the Order Detail/Confirmation page with a link to a form, but only when a certain product is purchased.

    If you want something similar, put this in the order_details.php template:

    global $woocommerce;
    
    $order = new WC_Order( $order_id );
    
    //This two lines above should already exist, but I have them here so you can see where I put my code
    
    	foreach($order->get_items() as $item) {
    		$_product = get_product($item['product_id']);
    		if ($item['product_id']==154) {
    // Do what you want here..replace the product ID with your product ID
    		}
    	}

    I also tested this by inserting a wp_redirect within the if statement and it seemed to work great, so I imagine you could customize this code with a bunch of if/elseif statements that redirect to different landing pages depending on the product purchased! Hopefully this helps someone!

  9. alaskatoargentina
    Member
    Posted 3 months ago #

    Any updates here?

    Just to clarify the request: WooCommerce customers would like to be able to specify a thank you page per product.

    Modifying the thankyou.php template affects every single product sold. : (

  10. Chee Studio
    Member
    Posted 3 months ago #

    @alaskatoargentina

    Um, yes...not to be too snide, but did you even try the code I posted above? It will redirect to a custom page if desired using wp_redirect based on product ID.

  11. cindyclemens
    Member
    Posted 3 months ago #

    @Chee Studio,

    Thank you very much for the code you provided.

    I have one small request :) I am still learning how to write things like that and do not know what to put where in order to actually have the product specific thank you page redirect part work.

    I see it looks like it would go in the "Do what you want here..replace the product ID with your product ID" spot, (duh :) ) but I do not know what to put there?

    Could you possibly throw some sample code in there that shows how to write the actual redirect to a page part?

    I would GREATLY appreciate it :)

    Even if no, thanks for pointing us all in the right direction. :)

    Cindy

  12. Chee Studio
    Member
    Posted 3 months ago #

    Hi @cindyclemens, sure!

    In my particular case, I wanted to display a link to a particular page, so for me, this is my code:

    foreach($order->get_items() as $item) {
    		$_product = get_product($item['product_id']);
    		if ($item['product_id']==154) {
    		echo '<h2 class="submit-script"> <a href="' . get_bloginfo('url') . '/step-2?first_name='.$order->billing_first_name. '&last_name=' . $order->billing_last_name . '&street=' . $order->billing_address_1 . '&addtwo=' .$order->billing_address_2 . '&city='.$order->billing_city. '&state='.$order->billing_state.'&zip='.$order->billing_postcode. '&email=' .$order->billing_email. '&phone=' .$order->billing_phone. '">Click here to submit your script now.</a></h2>' ;
    		}
    	}

    If I was going to do a redirect, here is what I would put:

    foreach($order->get_items() as $item) {
    		$_product = get_product($item['product_id']);
    		if ($item['product_id']==154) {
                     wp_redirect('http://www.yoururl.com/your-thank-you-page');
    		}
    	}

    Does this help you a bit more?

  13. ThreeBees
    Member
    Posted 3 months ago #

    I used Zapier! Awesome app.

  14. cindyclemens
    Member
    Posted 3 months ago #

    @Chee Studio,

    Thank you! For the quick response and the additional detail on the code. That looks perfect. I will save it and give it a try.

    Thank you, thank you, thank you! :)

    Have a great weekend,
    Cindy

  15. macrofit
    Member
    Posted 3 months ago #

    @Chee Studio

    Thanks for this, I have set up the redirect successfully for one product, how would I go about doing this for several products? Do I simply do this:

    foreach($order->get_items() as $item) {
    		$_product = get_product($item['product_id']);
    		if ($item['product_id']==154;155) {
                     wp_redirect('http://www.yoururl.com/your-thank-you-page');
    		}
    	}

    Or how do I do it?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic