Leave a Reply

3 comments

  1. You are going to want to insert your code at the top of the page templates for the Woo pages you would like the redirect to affect rather than the functions file. So for example if you want to redirect users when they try to access an individual product page you could put it at the top of the plugins->woocommerce->templates->single-product.php page.

    When editing templates though I would recommend making a copy and placing it in your theme directory, so that when Woo updates it will not override any changes you made. So for the example I gave above (applied to my theme). I would copy single-product.php and place it in the themes->agency file and then make the changes to that file, there. Your theme will then always use that file before the one in the Woo template file.

  2. First off never edit other peoples plugins or core wordpress files.

    Also use braces rather than pretty formatting, as pretty formatting breaks IDE code highlighting, brace matching, syntax checkers and other handy tools

    So put this code:

    // When default permalinks are enabled, redirect shop page to post type archive url
    if (is_user_logged_in() && isset($_GET['page_id']) && $_GET['page_id'] > 0 && get_option( 'permalink_structure' )=="" && $_GET['page_id'] ==     woocommerce_get_page_id('shop') ) {
        wp_redirect( get_post_type_archive_link('product') );
        die();
    }
    

    Either in:

    • the top of functions.php
    • A dedicated plugin
    • On the Init hook call
  3. Use the code functions.php:

    add_filter('woocommerce_login_redirect', 'wc_login_redirect');
    
    function wc_login_redirect( $redirect_to ) {
         $redirect_to = 'https://www.example.com/';
         return $redirect_to;
    }