[英]Woocommerce - Hide shop for unregistered user
我有一个woocommerce网站,当用户未登录时,我想隐藏商店。 我把这段代码放在文件中! archive-product.php,它位于woocommerce文件夹中的模板“ twentytwelve-child”中。
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
auth_redirect();
get_header( 'shop' ); ?>
通常,“ auth_redirect()”必须在登录页面中重定向我,但它不起作用。
我也尝试过使用此代码,但它也不起作用。
$login = is_user_logged_in();
if ($login == FALSE ) {
wp_redirect( home_url() );
exit;
}
我做错什么了吗?
谢谢。 我还添加了一些其他有用的功能。
// Redirect none registered users to a login page
function custom_redirect() {
if( (is_shop() || is_product() || is_product_category() ) && ! is_user_logged_in() ) {
wp_redirect( site_url( '/mon-compte' ) );
exit();
}
}
add_action("template_redirect","custom_redirect");
您无需为要实现的目的修改Woocommerce模板文件。 只需将以下代码添加到functions.php
function custom_redirect() {
if( is_shop() && ! is_user_logged_in() ) {
wp_redirect( home_url() );
exit();
}
}
add_action("template_redirect","custom_redirect");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.