On my site (using Woocommerce 3.2.6), I want to hide "Add to Cart" button only for logged in users.
I have this code:
add_action('init', 'hide_price_add_cart_logged_in');
function hide_price_add_cart_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 );
}
}
EDIT: Someone suggested me to use this:
add_action('init', 'hide_price_add_cart_logged_in');
function hide_price_add_cart_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 );
return WooCommerce::instance();
}
}
But that did not work...
I have inserted this code into functions.php file into my theme, but it don't seems to make any change. I still see add to cart button when check some product.
How to remove that button? Where is error in my function?