Dear team.
I added the following code to hide the (price/add to card) in every ware in the website and not display it until after logging in.
// Hide price until login
add_filter( ‘woocommerce_get_price_html’, ‘hide_price_until_login’, 10, 2 );
function hide_price_until_login( $price, $product ) {
if ( ! is_user_logged_in() ) {
return ‘Login to see prices‘;
}
return $price;
}
// Hide “Add to Cart” button until login
add_action( ‘woocommerce_single_product_summary’, ‘hide_add_to_cart_button’, 1 );
add_action( ‘woocommerce_after_shop_loop_item’, ‘hide_add_to_cart_button’, 1 );
function hide_add_to_cart_button() {
if ( ! is_user_logged_in() ) {
remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_add_to_cart’, 30 );
remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’, 10 );
}
}
But it didn’t work.
Please let me know the solution.