I am using the free Astra theme and default Astra header layout. Also I am using the WooCommerce plugin for shop. I select the “WooCommerce” under Customizer->Layout->Header->Last Item in Menu drop down list. It is showing the bag icon at right side of my header menu.
Now I am wanting to hide this icon for my Guest users. This means that logout users will not see this icon at header. So I used this following PHP snippet and added into my functions.php of Astra child theme.
1 2 3 4 5 6 7 8 9 10 11 12 |
/** * Removing the cart from astra header * Only logged in user can see this */ add_action( 'after_setup_theme', 'astra_remove_header_cart_icon'); function astra_remove_header_cart_icon() { if( is_user_logged_in() ) return; remove_filter( 'astra_get_dynamic_header_content', array( Astra_Woocommerce::get_instance(), 'astra_header_cart' ), 10, 3 ); } |
is_user_logged_in() function is checking that a user is logged in to site or not. If user is not logged in, it will remove the filter astra_get_dynamic_header_content and the complete HTML markup of cart icon from header.
Ric says
Hello I am using ultimate member plugin and my website is only available to logged in people , but I don’t know how to hide the shopping cart icon, I applied your code on functions.php but dosn’t work, hope you can help me