Welcome to the Marketist Blog!
Are you looking to add a touch of exclusivity to your WooCommerce store?
Imagine creating a shopping experience where only registered users get the privilege of viewing your product prices—enticing visitors to join your community before they even consider making a purchase.
Whether you’re running a wholesale business, a members-only shop, or simply want to keep your pricing strategy private, this powerful technique will elevate your store’s appeal and boost customer engagement.
Ready to unlock the secret? Let’s get started!
We’ll be using the Code Snippets plugin to safely add custom code to your WordPress site. Let’s dive in!
Why Hide Product Prices?
Hiding product prices from non-logged-in users offers several benefits:
- Exclusive Pricing: Provide special prices to registered users or members.
- Lead Generation: Encourage visitors to create an account to view prices.
- Privacy: Keep your pricing strategy confidential from competitors.
Step-by-Step Guide to Hide Product Prices:
1. Install and Activate the Code Snippets Plugin
- Go to your WordPress dashboard.
- Navigate to Plugins > Add New.
- Search for Code Snippets.
- Click Install Now and then Activate.
2. Add the Custom Code Snippet
- Once the plugin is activated, go to Snippets > Add New.
- Give your snippet a title, such as “Hide Product Prices for Non-Logged In Users”.
3. Insert the Code
Copy and paste the following code into the Code Snippet editor:
// Hide prices
add_action('after_setup_theme', 'marketist_activate_filter');
function marketist_activate_filter() {
add_filter('woocommerce_get_price_html', 'marketist_show_price_logged');
}
function marketist_show_price_logged($price) {
if (is_user_logged_in()) {
return $price;
} else {
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10);
return 'Login to order';
}
}
// Option Two (If you decided to use Option One then don’t add the following code)
add_filter('woocommerce_is_purchasable', 'marketist_woocommerce_is_purchasable', 10, 2);
function marketist_woocommerce_is_purchasable($is_purchasable, $product) {
$isLoggedIn = is_user_logged_in();
if ($isLoggedIn) {
// Make product purchasable to logged-in users
return true;
}
// Make product not purchasable to unlogged-in users
return false;
}
4. Save and Activate the Snippet
After pasting the code, click Save Changes and Activate.
5. Verify the Functionality on the Frontend
- Log out of your WordPress account.
- Visit your WooCommerce store and navigate to any product page.
- You should see a “Login to order” message instead of the product price.
Customization Tips
- Message Customization: Edit the link text in the code to align with your store’s tone.
- Styling: Use CSS to style the “Login to order” link to match your site’s design.
- User Experience: Ensure your login and registration pages are user-friendly to convert visitors into registered users.
Conclusion
By following these steps, you can easily hide product prices from non-logged-in users on your WooCommerce store, offering a more exclusive experience and encouraging user registration. This simple method can significantly enhance the functionality and appeal of your store.
If you have any questions or need further assistance, feel free to leave a comment. Stay tuned for more WooCommerce tips and tricks on the Marketist Blog!