Hide prices and cart buttons if user not logged in

You can restrict the display of prices and only allow items to be added to the cart for logged in users. This might be useful if, for example, you are a wholesaler and only want your retail clients to be able to see your prices.

/**
 * Hide prices and cart buttons if user not logged in
 */

add_action('init', 'sc_woo_hide_price_add_cart_not_logged_in');

function sc_woo_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', 'sc_woo_print_login_to_see_prices', 31);
    add_action('woocommerce_after_shop_loop_item', 'sc_woo_print_login_to_see_prices', 11);
  }

}

function sc_woo_print_login_to_see_prices() {

  echo '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '">' . __('Login to see prices', 'theme_name') . '</a>';

}