2014-11-07 4 views
0

woocommerce 웹 사이트가 있습니다. 사용자가 로그온하지 않은 경우 상점을 숨기고 싶습니다. 이 코드를 파일에 넣었습니다! archive-product.php는 woocommerce 폴더의 'twentytwelve-child'템플릿에 있습니다.Woocommerce - 등록되지 않은 사용자를위한 상점 숨기기

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; 
} 

내가 잘못 했습니까?

답변

0

달성하려는 작업에 대해 Woocommerce 템플릿 파일을 수정할 필요가 없습니다. 그냥 function.php에 다음 코드를 추가하십시오.

function custom_redirect() {   
    if(is_shop() && ! is_user_logged_in()) { 
     wp_redirect(home_url()); 
     exit(); 
    } 
} 

add_action("template_redirect","custom_redirect"); 
1

감사합니다. 또한 도움이 될 수있는 몇 가지 다른 기능을 추가합니다.

// 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"); 
관련 문제