VirtueMart

WooCommerce

Others

Docs

Support

Demo

Blog

About

Forum

We are currently unable to provide proper support!

For the last few months we have been very busy working on some huge, very time-consuming and time-sensitive projects, so our support was very limited and we were unable to provide proper support in our forums! We now have a huge backlog of requests from our customers, which we are trying to clear bit by bit. Unfortunately, this takes longer than we anticipated, so our response time is not yet up to par. We are trying our best to improve this situation as soon as possible.

Sorry for the inconvenience and thank you for your understanding!

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 https://www.wpblog.com/add-to-cart-button-in-woocommerce-store/ 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):
<?php
/**
 * Plugin Name: Disable Add Button
 * Plugin URI: http://www.open-tools.net/
 * Description: Disables the Add to Cart button for hardcoded products (identified by product ID in the php code)
 * Author: OpenTools
 * Author URI: http://www.open-tools.net
 * 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,
Reinhold

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

  • Page:
  • 1

VM - Shopping cart

 x 

Cart empty

Login Formular