Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: I am trying to disable add to cart button

I am trying to disable add to cart button 22 Feb 2018 11:11 #1

  • alexanderbiscajin
  • alexanderbiscajin's Avatar Topic Author
  • Offline
  • Posts: 2
I want to disable the add to cart button for specific products and going through the tutorial I have pasted the code in function.php but still the button is showing there. Can you help me out in the code ?

add_filter('woocommerce_is_purchasable', 'watchblog_specific_product');
function watchblog_specific_product($purchaseable_product_watchblog, $product) {
return ($product->id == specific_product_id (512) ? false : $purchaseable_product_watchblog);

Please Log in or Create an account to join the conversation.

I am trying to disable add to cart button 24 Feb 2018 22:29 #2

Dear Alexander,
I just tried the code, and it works in principle. There are some minor changes required to make it work, though:
add_filter('woocommerce_is_purchasable', 'wpblog_specific_product', 10, 2);
function wpblog_specific_product($purchaseable_product_wpblog, $product) {
        return ($product->id == 11 ? false : $purchaseable_product_wpblog);
Notice that a) you need the two extra arguments to the add_filter call, otherwise the $product object is NOT passed on to your filter function, and b) you need to compare the product ID with the actual ID of your product (in my case, the product I tried to filter has ID 11).

As written in the wpblog entry, you can place this code in wp-content/themes/[YOURTHEME]/functions.php, but that will be overwritten by theme updates. So it's way better to place it into a tiny plugin (e.g. wp-content/plugins/disable-add-button/disable-add-button.php):
 * Plugin Name: Disable Add Button
 * Plugin URI:
 * Description: Disables the Add to Cart button for hardcoded products (identified by product ID in the php code)
 * Author: OpenTools
 * Author URI:
 * Version: 0.1
 * Text Domain: disable-add-button

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

add_filter('woocommerce_is_purchasable', 'wpblog_specific_product', 10, 2);
function wpblog_specific_product($purchaseable, $product) {
        return ($product->id == 11 ? false : $purchaseable);
Don't forget to activate that plugin (simply placing the file in the location I gave above is sufficient to "install" the plugin).

Best regards,

Please Log in or Create an account to join the conversation.

  • Page:
  • 1

VM - Shopping cart


Cart empty

Login Formular