skip to Main Content

I have been struggling with this idea where i would want to auto close the woocommerce thank you page after 1 minute or so, but am unable to find a way out. The reason behind the same is because we are tracking it with Facebook Pixels. So, 1 views is counted as a sale.

So, we need to ensure, the customer can only view it once and not revisit it again. Is is possible?

2

Answers


  1. You can redirect to any page after 1 minute from WooCommerce thank you page. I have tried below code to redirect to a home page after 60 seconds from thank you page.

    add_action('template_redirect', 'custom_redirect_after_purchase');
    
    function custom_redirect_after_purchase() {
    
        global $wp;
    
        if (is_checkout() && !empty($wp->query_vars['order-received'])) {
            header( "refresh:60;url=".home_url() );
        }
    }
    

    I hope this helps you to achieve what you want.

    Login or Signup to reply.
  2. Another way to redirect using PHP and WordPress is like below you can try this

    add_action('template_redirect', 'custom_redirect_after_purchase');
    
    function custom_redirect_after_purchase() {
    
        global $wp;
    
        if (is_checkout() && !empty($wp->query_vars['order-received'])) {
            sleep(60);
            wp_redirect( home_url() ); exit;
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search