How to Disable Add to Cart in WooCommerce and Redirect to Product Page
WooCommerce is a powerful eCommerce platform for WordPress, but sometimes you may want to disable the “Add to Cart” button and instead direct customers to the product page. This is useful for stores that require customers to read detailed product descriptions before purchasing or for catalog-style websites that showcase products without direct selling.
In this guide, we’ll show you how to remove the “Add to Cart” button and ensure customers are directed to the product page using a simple code snippet. We’ll also provide a plugin-based method for users who prefer not to edit code manually.
Why Disable the Add to Cart Button?
Disabling the “Add to Cart” button can be beneficial for:
- Catalog-style websites – Display products without allowing direct purchases.
- Lead generation – Encourage visitors to contact you before purchasing.
- Custom ordering processes – If you require customizations before purchase.
- Out-of-stock management – Prevent purchases while keeping products visible.
Code Snippet to Remove Add to Cart in WooCommerce
To remove the “Add to Cart” button and redirect users to the product page, add the following snippet to your theme’s functions.php
file:
// Redirect Add to Cart button to Product Page
add_filter('woocommerce_product_add_to_cart_text', function() {
return __('View Product', 'woocommerce');
});
add_filter('woocommerce_loop_add_to_cart_link', function($button, $product) {
return sprintf('<a href="%s" class="button">%s</a>', esc_url(get_permalink($product->get_id())), __('View Product', 'woocommerce'));
}, 10, 2);
// Remove Add to Cart button on Single Product Page
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
How This Code Works:
- Modifies the Add to Cart button to show “View Product” instead.
- Redirects users to the product page instead of adding to the cart.
- Removes the Add to Cart button from single product pages.
Alternative: Use a Plugin to Disable Add to Cart Button
If you’re not comfortable editing code, you can use a plugin like Code Snippets to safely add the code without modifying functions.php
. Follow these steps:
- Install and activate the Code Snippets plugin.
- Go to Snippets > Add New.
- Give your snippet a title (e.g., “Disable Add to Cart”).
- Copy and paste the above code into the snippet editor.
- Select “Run snippet everywhere.”
- Click Save and Activate.
Final Thoughts
Disabling the “Add to Cart” button in WooCommerce can enhance user experience and better align your store with your business model. Whether you choose the code snippet or the plugin method, you can easily control how customers interact with your products.