
WooCommerce: Hide Price & Add to Cart for Logged Out Users
If you require only logged in users to be able to see prices in woocomerce, here is how you can do it.
Add the following to the bottom of your themes functions.php file.
add_action( 'init', 'mystore_hide_price_add_cart_not_logged_in' ); function mystore_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', 'mystore_print_login_to_see', 31 ); add_action( 'woocommerce_after_shop_loop_item', 'mystore_print_login_to_see', 11 ); } } function mystore_print_login_to_see() { echo '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '">' . __('Login to see prices', 'theme_name') . '</a>'; }