Trying to remove the add to cart button only from product in the product loop and add some text instead.
The following code does remove the button, but also from all buttons after the condition has been validated:
function remove_purchase_buttons_from_loop() {
if( $product->id == $_product->id ) {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
add_action( 'woocommerce_after_shop_loop_item', 'level_already_in_cart_notice', 10 );
}
}
add_action ('woocommerce_before_shop_loop_item', 'remove_purchase_buttons_from_loop'));
I understand why this happening but what is the right solution
Try this
I hope this will help you.