UserWoocommerce

Hide Price & Add to Cart Button for Logged Out Users in WooCommerce

You can improve the functioning of your WooCommerce store by making the add-to-cart button and prices hidden from users who aren’t logged in. This excerpt guarantees that product prices and purchase transactions can only be viewed by logged-in users. A notification asking a visitor to log in in order to view prices will appear if they are not logged in.

Membership-based retailers and wholesalers who need to limit access to pricing information to logged-in consumers may find this feature especially helpful. You may promote account creation and guarantee that only authorized users are able to make purchases by requiring visitors to log in before they can view prices. This adds an extra degree of security to your store and helps safeguard your pricing strategy.

The Advantages of Not Showing Prices to Logged-Out Users

There are various benefits to hiding prices and the add-to-cart button for logged-out customers. It establishes a private space where only logged-in users have access to the complete product specifications, encouraging additional sign-ups and a feeling of community among your clientele. It also aids in keeping price confidential, which is beneficial in wholesale or competitive marketplaces. By using this feature, your WooCommerce store’s overall security and functionality can be improved as well as user engagement.

    
//Hide Price & Add to Cart Button for Logged Out Users in WooCommerce add_filter( 'woocommerce_get_price_html', 'hide_price_addcart_not_logged_in', 9999, 2 ); function hide_price_addcart_not_logged_in( $price, $product ) { if ( ! is_user_logged_in() ) { $price = '<div><a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">' . __( 'Login to see prices', 'wpsnippetclub' ) . '</a></div>'; remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ); add_filter( 'woocommerce_is_purchasable', '__return_false' ); } return $price; }

Leave a Reply

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