What plugin are you using for the eCommerce functionality?
Thread Starter
cassr
(@cassr)
woocommerce free services only
In that case, I recommend asking at https://ww.wp.xz.cn/support/plugin/woocommerce so the plugin’s developers and support community can help you with this.
Hi,
Please put this code in your child theme’s functions.php file.
add_action( 'template_redirect', 'ps_shop_redirect' );
function ps_shop_redirect() {
if ( !is_user_logged_in() && is_page( 'shop' )) {
wp_redirect( home_url() );
exit;
}
}
Now when any of your visitors(non-logged in users) will try to access shop page then they will be redirected to home page of your site.
Thanks
Thread Starter
cassr
(@cassr)
I dont have a child theme. Isnt there an easier way?
Please install this plugin https://ww.wp.xz.cn/plugins/code-snippets/ and add my code as a new snippet there. You can check in plugin’s screenshots how to do that.
Thread Starter
cassr
(@cassr)
installed code snippet, add your code but it didnt work
Thread Starter
cassr
(@cassr)
Im using elementor and oceanwp theme
What’s happening there when you are logged out and trying to access shop page and what’s the shop page slug?
Thread Starter
cassr
(@cassr)
slug is shop. when I log out I can still access mydomain/shop page
Please try this:
add_action( 'template_redirect', 'ps_shop_redirect' );
function ps_shop_redirect() {
if ( is_shop() && !is_user_logged_in()) {
wp_redirect( home_url() );
exit;
}
}
I did a minor change from is_page to is_shop.
It should work now, please resolve if it worked for you.
Hi,
I am experiencing the same issue. I am trying to redirect all woocommerce pages to the account section. The idea is to have a private Woocommerce site. Here is what I have:
`function wpse_131562_redirect() {
if(!is_user_logged_in() && $pagenow != ‘wp-login.php’)
{
if ( is_woocommerce() || is_shop() || is_cart() || is_checkout())
{
wp_redirect(site_url(‘account/’));
exit;
}
}
}
add_action(‘template_redirect’, ‘wpse_131562_redirect’);
`
Is not working with WordPress 5.0 and latest Woocommerce version.