2015-11-19 63 views
0

我試圖隱藏以下內容的Content-product.php來賓用戶的登錄內部用戶(使其不可見用戶未註冊):Woocommerce隱藏具體內容未在

<?php if(get_field('___unit_price')): ?> 
<p>Unit Price: $<?php the_field('___unit_price'); ?></p> 

對於我的生活,我無法讓它隱藏起來。任何幫助,將不勝感激。

回答

1

您需要更多的條件邏輯。

如果 get_field()函數返回一個值,但你還需要檢查用戶是否登錄。便利
<?php if(get_field('___unit_price')): ?> 
<p>Unit Price: $<?php the_field('___unit_price'); ?></p> 

只檢查,WordPress的有一個名爲is_user_logged_in()函數來檢查這一點。

<?php if(is_user_logged_in() && get_field('___unit_price')): ?> 
<p>Unit Price: $<?php the_field('___unit_price'); ?></p> 
<?php endif; ?> 
+0

謝謝!那樣做了。在一個例子中,我很接近,但我認爲我搞砸了代碼。你的伎倆! –