WooCommerce: How to remove the add to cart button from specific products

Here’s how you can remove the “Add to cart” button from specific products in your WooCommerce store (per ID)

Remember to replace

id1, id2, id3

with the IDs of the product’s you’d like to remove the button from. If you need help finding the product IDs, please see https://bobwp.com/find-product-id-woocommerce/

    Archive/shop page:
add_filter( 'woocommerce_loop_add_to_cart_link', 'remove_add_to_cart_buttons_archive', 1 );
function remove_add_to_cart_buttons_archive( $button ) {
    global $product;

    $products_with_no_buttons = array( id1, id2, id3 ); 

    if ( in_array( $product->get_id(), $products_with_no_buttons ) ) {
        return '';
    }

    return $button;
}
    Single product pages:
add_action( 'woocommerce_single_product_summary', 'remove_add_to_cart_button_single_products', 1 );
function remove_add_to_cart_button_single_products() {
    global $product;

    $products_with_no_buttons = array( id1, id2, id3 );
    if ( is_single() && in_array( $product->get_id(), $products_with_no_buttons ) ) {
        remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
    }
}


Was this helpful? Please buy me a coffee






This code should be added to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as the Code snippets plugin. Please don’t add custom code directly to your parent theme’s functions.php file as this will be wiped entirely when you update.

Share your thoughts

Your email address will not be published. Required fields are marked *