Hide Product Prices For Users On WooCommerce | Login To Order

Hide WooCommerce prices

Welcome to Aqib Hameed’s Blog! In this post, we will show you how to hide product prices from non-logged-in users in your WooCommerce store, encouraging them to log in to view prices and place orders. This approach is perfect for wholesale stores, member-only shops, or any e-commerce business that wants to offer prices exclusively to registered users.

We’ll use the Code Snippets plugin to safely add custom code to your WordPress site. Let’s get started!

Why Hide Product Prices?

There are several benefits to hiding product prices from non-logged-in users:

  • Exclusive Pricing: Offer special prices to registered users or members.
  • Lead Generation: Encourage visitors to create an account to view prices.
  • Privacy: Keep your pricing strategy private 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', 'magik_activate_filter');
    function magik_activate_filter() {
        add_filter('woocommerce_get_price_html', 'magik_show_price_logged');
    }
    function magik_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', 'my_woocommerce_is_purchasable', 10, 2);
    function my_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;
    }
                
  1. Save and Activate the Snippet
    • After pasting the code, click Save Changes and Activate.
  2. 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 fit 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 help 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, providing a more exclusive experience and encouraging user registration. This method is straightforward and 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 Aqib Hameed’s Blog!

Leave a Reply

Your email address will not be published. Required fields are marked *