@alanfrys, If you aren’t concerned with what role the user has (basic roles:administrator, editor, author, subscriber) but only if the user is logged in (which is typically a subscriber) then try the … wait for it … is_user_logged_in() function.
Example:
if ( is_user_logged_in() ) {
[
whatever template part is used to get these elements:
<span class="details"></span>
<span class="details"></span>
<span class="details"></span>
<span class="details"></span>
<div class="woocommerce-product-details__short-description"></div>
]
} else {
echo '<a href="/wp-login.php">Login</a> to see details.';
}
Hope that helps.
To clarify, the brackets [ ] and their contents should not be used.
replace with something more along the lines of php like
get_template_part('template-parts/item-details');
So that would be:
if ( is_user_logged_in() ) {
get_template_part('template-parts/item-details');
} else {
echo '<a href="/wp-login.php">Login</a> to see details.';
}
-
This reply was modified 4 years, 10 months ago by
Nic Winn.
Thank you for the answer!
// showing on single product page
add_action(‘woocommerce_single_product_summary’,’show_product_code’,13);
function show_product_code(){
global $product;
if ( empty( $product ) ) {
return;
}
But im confused, that code its what i want to hide for non log in users. Below that there are many options, so woocommerce_single_product_summary its the template? i dont know how can i add that and hide the information, i tried but doesnt work obviusly there are thing im doing wrong.
If you can help me could be amazing, maybe its dificult to me because i am not a developer.
Thank you!