You may want to force users to login in order to see prices and add products to cart.

All you need is pasting the following code in your functions.php (please note: your theme may have overwritten some default WooCommerce functions, hence the code below may not work. Contact me if you need custom code). Enjoy!

woocommerce-hide-prices-add-cart-shop-single-productwoocommerce-hide-prices-add-cart-shop-single-product
WooCommerce: Hide Price & Add to Cart to Logged Out Users

PHP Snippet: hide add to cart and price if logged out @ WooCommerce Shop & Single Product Page

/**
 * @snippet       Hide Price & Add to Cart for Logged Out Users
 * @how-to        Get CustomizeWoo.com FREE
 * @sourcecode    https://businessbloomer.com/?p=299
 * @compatible    WooCommerce 3.6.2
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
add_action( 'init', 'bbloomer_hide_price_add_cart_not_logged_in' );
 
function bbloomer_hide_price_add_cart_not_logged_in() {   
if ( ! is_user_logged_in() ) {      
 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 );
 remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
 remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );   
 add_action( 'woocommerce_single_product_summary', 'bbloomer_print_login_to_see', 31 );
 add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_print_login_to_see', 11 );
}
}
 
function bbloomer_print_login_to_see() {
echo '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '">' . __('Login to see prices', 'theme_name') . '</a>';
}
Share:

Leave a Reply