exist WooCommerce In an e-commerce site, we sometimes want to provide theAdditional information for logged-in users, such as members-only offers, hidden content descriptions, and wholesale prices. And visitors who are not logged in can only see basic information to guide them to register or log in.
this kind of functionalityNo need to install plug-ins, which takes only a few lines of code to implement:
- Specified content visible to logged-in users
- Non-logged-in users see prompts to log in/register
This tutorial will show you how to easily implement the "Login Visible" feature in WooCommerce product detail pages with code that is secure, lightweight, and customizable.
![图片[1]-登录用户看到隐藏信息?用代码轻松搞定(适用于 WooCommerce 产品页)](https://www.361sale.com/wp-content/uploads/2025/06/20250624110311813-image.png)
I. Examples of applicable scenarios
- Show members-only offers or price descriptions
- Display "Purchase Instructions" for logged-in users only.
- Display prices or contact information visible to wholesale customers
- Encourage user registration: prompt "login to view more content" when not logged in
Second, the code implementation: login user visible content
Add the following code to the current theme's functions.php Documentation:
Open the path as:Backend - Appearance - Theme File Editor–functions.php
![图片[2]-登录用户看到隐藏信息?用代码轻松搞定(适用于 WooCommerce 产品页)](https://www.361sale.com/wp-content/uploads/2025/06/20250624111047241-image.png)
add_action( 'woocommerce_single_product_summary', 'show_content_for_logged_in_users', 35 );
function show_content_for_logged_in_users() {
if ( is_user_logged_in() ) {
echo '<div class="custom-member-content">'; echo '
echo '<strong>🎉 Members Only:</strong> Free 20 off coupon for orders over 100!' ;
echo '</div>'; } else {
} else {
echo '<div class="custom-guest-message">'; echo 'Please start first.
echo 'Please first <a href="/en/' . wp_login_url( get_permalink() ) . '/">log in</a> maybe <a href="/en/' . wp_registration_url() . '/">enrollment</a> Check out more deals later.' ;
echo '</div>';
}
}
III. Description and extension
- The code uses WooCommerce hooks
woocommerce_single_product_summaryInserted after the "Add to Cart" button. is_user_logged_in()be WordPress Built-in function to determine if a user is logged inwp_login_url()respond in singingwp_registration_url()Generate links to login/registration pages
Fourth, the page effect preview
Not seen by logged in users:
Please login or register to view more offers.
Logged in users see:
🎉 Exclusive for members: 20 off coupon for 100 off when you place an order!
![图片[3]-登录用户看到隐藏信息?用代码轻松搞定(适用于 WooCommerce 产品页)](https://www.361sale.com/wp-content/uploads/2025/06/20250624114114846-image.png)
You can replace the text content, button styles, add images, etc. in them as needed to achieve personalized effects.
V. Advancement recommendations (optional)
If further control of the display is desired:
- Display different information according to user roles (e.g. only for "wholesale customers")
- Hide the content with the
get_field()combining ACF Plugin Dynamic Fetch - utilization
current_user_can()Determine if a user with specific privileges
Sample code (shown by role):
if ( current_user_can( 'wholesale_customer' ) ) {
echo 'This is what wholesale customers see.' ;
}
VI. Summary
With simple code judgments, it can be easily implemented in the WooCommerce Showing different content for different users in the product page can enhance the member experience and effectively guide visitors to register.
Link to this article:https://www.361sale.com/en/62569/The article is copyrighted and must be reproduced with attribution.





















![表情[wozuimei]-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/themes/zibll/img/smilies/wozuimei.gif)
![表情[baoquan]-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/themes/zibll/img/smilies/baoquan.gif)

No comments