Hide price and cart until login

  • Resolved
    Posted in: Highend WP Theme  
  • Customer
    Art Department
    January 15, 2020 at 6:37 pm #144530

    Hi
    I have our store set up pretty much the way they want it, but there is one issue I haven’t figured out. I was able to hide the price until login with a snippet:

    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 );
    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 20 );
    add_action( ‘woocommerce_template_single_price’, ‘bbloomer_print_login_to_see’, 21 );
    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 ‘‘ . __(‘<button class=”cartbutton2″>LOG IN TO SEE PRICES</button>‘) . ‘‘;
    }

    But unfortunately, when I moved price into the same area as cart:

    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 10 );
    add_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 30 );

    The price no longer hides, so I have to things to ask:
    1) How to I make price hide now, and
    2) Is there a way to make bot the price and car hide altogether until login?

    They want the store to look as much unlike a store for the non-signed-in, non-customers who visit the site.

    Attachments:
    You must be logged in to view attached files.

    Sorry, this forum is for verified users only. Please Login or Register to continue

Comments are closed.