• Hi,
    My website’s expected behavior is to hide add_to_cart button if the user isn’t logged in. However, the first product on the archive page still has the button. Here’s the code:

    add_action('after_setup_theme','activate_filter') ;
     
    function activate_filter(){
    add_filter('woocommerce_get_price_html', 'bbloomer_show_price_logged');
    }
     
    function bbloomer_show_price_logged(){
    	if(!is_user_logged_in() ){
    		remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
    		remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
    		remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
    		remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
    	}
    }
    

    website: https://www.viva-viva.ru

    Please help! Also, is there a way not to open a cart sidebar when add_to_cart is clicked?

    Thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • Mina

    (@purpleberryservices)

    Change remove action
    remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’);

    To This:
    remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’, 10 );

    Thread Starter levdavid

    (@levdavid)

    Doesn’t change anything. One hacky way to solve it is to add a login check for catalog_mode flag inside a parent theme. However, it will die every time I update.

    Mina

    (@purpleberryservices)

    Ok. But changing something in Parent Theme is not an good idea.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add to cart is not hidden for the first product’ is closed to new replies.