Redirect to Different Pages for Different Products After Checkout in WooCommerce Without a Plugin

Поделиться
HTML-код
  • Опубликовано: 12 сен 2024
  • The function required to do this is pinned 📌 to the top comment.
    Relevant videos:
    How to automatically redirect users from any page to any page, website or domain in WordPress: • Automatically Redirect...
    How to redirect users to a custom thank you page after checkout in WooCommerce: • Redirect to a Custom T...
    How to create a child theme in WordPress: • The Fastest, Easiest W...
    After your customers purchase something in WooCommerce, they're redirected to a basic thank you page. That happens no matter what they buy. But there's a very easy way to redirect them to different pages based on which products they purchase. So if they purchase product A, you can redirect them to thank you page A. For product B, you can redirect them to thank you page B. You can do this for as many different products as you want.
    If you combine this with a basic custom thank you page, you can make sure your visitors never land on the default, bland WooCommerce thank you page. That can improve the user experience, the customer satisfaction and brand awareness. It's an easy way to make sure your customers feel even better about your brand after purchasing your product.
    Make sure you use a child theme and back up your WordPress website before doing this!
    #WooCommerce #checkout #redirect
    What I use to build amazing websites:
    Elementor: be.elementor.c...
    Hosting I love and recommend for most clients and for those on a budget: www.hostg.xyz/...
    🧙 Wizards of Webcraft - A series where I’ll be reviewing your websites - www.reialesa.c... Apply now!
    Get in touch:
    www.reialesa.c...
    Don’t be shy! Let me know what you’d like to see next, ask me anything related to design or just simply say hi.
    Please note that some of the above are affiliate links, which means I earn a commission if you make a purchase, at no additional cost to you. Thank you very much if you decide to use them!

Комментарии • 25

  • @Reialesa
    @Reialesa  Год назад +4

    Relevant videos:
    How to automatically redirect users from any page to any page, website or domain in WordPress: ruclips.net/video/7ZtnlkP0f08/видео.html
    How to redirect users to a custom thank you page after checkout in WooCommerce: ruclips.net/video/scwoeFpl-fM/видео.html
    How to create a child theme in WordPress: ruclips.net/video/iRGn5Ypm1qw/видео.html
    The function required to do this 👇
    /**
    * WooCommerce - Redirect to different custom thank you pages based on products purchased after checkout
    */
    add_action( 'template_redirect', 'reialesa_different_thank_you_pages_for_different_products' );

    function reialesa_different_thank_you_pages_for_different_products(){

    if( !is_wc_endpoint_url( 'order-received' ) || empty( $_GET['key'] ) ) {
    return;
    }

    $order_id = wc_get_order_id_by_order_key( $_GET['key'] );
    $order = wc_get_order( $order_id );

    foreach( $order->get_items() as $item ) {
    if( $item['product_id'] == 123 ) { // add in your product ID here
    wp_redirect( 'your URL here' ); // add in your custom thank you page URL here
    exit;
    }
    }
    }

    • @jaytothe9633
      @jaytothe9633 Год назад

      Thanks so much for this video, it's great 😀 is there a way to do this based on product category?

  • @Kickmug
    @Kickmug 3 месяца назад

    wow this thing is working, this is best when you selling service then you make custom thank you page and further give them scheduling meeting link then you do meeting and give them upwork direct contract option

  • @SallyHoward-j3p
    @SallyHoward-j3p 5 месяцев назад +1

    LEGEND thank you so much! wanted to create a tripwire page for an specific offer and this works perfect

    • @RyanMolkentin
      @RyanMolkentin 5 месяцев назад

      saaaame, Reialesa is great for this

    • @Reialesa
      @Reialesa  3 месяца назад

      Awesome, that's great to hear. I'm glad you found a good use for this. Thank you for your support, I appreciate it! 🙌

    • @Reialesa
      @Reialesa  3 месяца назад

      Right back at you Ryan, thank you for your kind words! 🙏

  • @netguy
    @netguy 2 месяца назад

    Thank you for this video and easy-to-use function, this is brilliant!
    P.S: It is worth mentioning that for people who are not using a child theme or don't want to use one and are not comfortable changing theme files,
    they can use a free code snippet plugin and enter this function code as a snippet there instead.
    Cheers

  • @LeonardoSouza-mg9qc
    @LeonardoSouza-mg9qc 5 месяцев назад

    Thank you! It works like a charm. So, and if I want to do a redirect only in cases that the payment was refused? Or better, add an different URL when payments was refused?

  • @englishcabbage23
    @englishcabbage23 5 месяцев назад

    You're the best!

    • @Reialesa
      @Reialesa  3 месяца назад

      Right back at you! 🫵 Thank you for your kind comment, I really appreciate it. 🙏

  • @linguastar
    @linguastar 11 месяцев назад

    cool! thanks man!

    • @Reialesa
      @Reialesa  10 месяцев назад

      I'm happy to help, thank you for your support! 🙌🙏

  • @user-bl1mf8iq8b
    @user-bl1mf8iq8b 6 месяцев назад

    This doesn't seem to be working with the newest version of WordPress. Are you seeing any issues or have updated code?

  • @lilstunna
    @lilstunna 9 месяцев назад

    You mentioned using a child theme. My question is does that mean that child themes never gets updated in Wordpress? Does the website become vulnerable after months of using a theme that has not been updated?

    • @Reialesa
      @Reialesa  7 месяцев назад +1

      Great question! Child themes allow you to keep the changes you made to certain files when the main theme gets updated. You can't update child themes because they're not full themes. They're just certain files that you can edit, such as functions.php. If the functions inside of that file cause vulnerabilities, the website can become vulnerable, but it has nothing to do with the child theme directly.
      If the main (parent) theme gets updated, you will see those updates on your website even if you're using a child theme. And you can't use a child theme without having the parent theme installed. In short, you don't have to worry about updates when it comes to your child theme. If you regularly create backups, update your parent theme and test everything out, you should have no issues. 💪

    • @lilstunna
      @lilstunna 7 месяцев назад

      @@Reialesa thank you for the info!

    • @Reialesa
      @Reialesa  7 месяцев назад

      I'm happy to help, thank you for your support! 🙌

  • @g-educates
    @g-educates Год назад

    Thanks alot man

    • @Reialesa
      @Reialesa  Год назад

      I'm happy to help, thank you for your support! 🙏

  • @connectadnan4669
    @connectadnan4669 Год назад

    Hi, what is the snippet if I want to redirect customers to custom thank you page for only Virtual Products ?

    • @Reialesa
      @Reialesa  Год назад +1

      Hi! I would recommend you create a special category for your virtual products. Then, you can redirect based on the category of the purchased product(s).
      I haven't tested it out myself because I am currently unable to do so, but here are some things you can check out to point you in the right direction:
      stackoverflow.com/questions/62619654/woocommerce-custom-checkout-page-redirection-for-specific-product-categories
      stackoverflow.com/questions/51941923/redirect-when-buying-products-from-a-certain-product-category-in-woocommerce
      Let me know how it goes! 💪

  • @cybermenwp
    @cybermenwp 5 месяцев назад

    How to change with product category

    • @Reialesa
      @Reialesa  3 месяца назад

      That's a great question and a good idea for a video! For now, I can point you in the right direction, hopefully this will help you out: stackoverflow.com/questions/51941923/redirect-when-buying-products-from-a-certain-product-category-in-woocommerce

  • @fabrictexture4767
    @fabrictexture4767 Год назад +1

    /**
    * Redirect WooCommerce to a custom page after checkout
    */
    add_action( 'woocommerce_thankyou', 'reialesa_redirect_woo_checkout');
    function reialesa_redirect_woo_checkout( $order_id ){
    $order = wc_get_order( $order_id );
    $url = 'XYZ/';
    if ( ! $order->has_status( 'failed' ) ) {
    wp_safe_redirect( $url );
    exit;
    }
    }