I want to disable the 'add to cart' button if the product is already added. I have managed to change the. test for an already added product so that it says 'Already added' for the button. The code or that is below. I just don't know how to disable that button in addition to that text change.
add_filter('woocommerce_product_add_to_cart_text', 'wc_product_add_to_cart_text', 10, 2 );
add_filter('woocommerce_product_single_add_to_cart_text', 'wc_product_add_to_cart_text', 10, 2 );
function wc_product_add_to_cart_text( $text, $product ){
$product_cart_id = WC()->cart->generate_cart_id( $product->get_id() );
$in_cart = WC()->cart->find_product_in_cart( $product_cart_id );
if ( $in_cart ) {
$text = "Already added";
}
return $text;
}