I am currently using woocommerce and would like to redirect none logged in users to the home page, however i am having a little trouble determining where i should implements this
I have done research and determined that using the is_user_logged_in() i can see if the user is logged in.
I tryed implementing in the woocommerce/woocommerce-functions.php
// 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_safe_redirect( get_post_type_archive_link('product') );
exit;
endif;
but it still allows the page to be visible
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.
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:
Either in:
Use the code
functions.php
: