Login
Register

VirtueMart

WooCommerce

Others

Docs

Support

Blog

About

Ordernumbers for WooCommerce

IMPORTANT ANNOUNCEMENT: Plugin development ceased, all plugins made available freely (GPL)

With great sadness we have to announce that we are ceasing development of all our VirtueMart, WooCommerce and Joomla plugins. Effective immediately, all our plugins -- even those that were paid downloads -- are made available for free from our homepage (GPL license still applies), but we cannot and will not provide any support anymore.

It has been a great pleasure to be part of the thriving development communities of VirtueMart as well as WooCommerce. However, during the last year it became painstakingly clear that in addition to a full-time job, a young family and several other time-consuming hobbies at professional level (like being a professional singer) the plugin development and the support that it requires is not sustainable and is taking its toll. It has been an honor, but it is now time to say good bye!

×

Notice

The forum is in read only mode.
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

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

  • alexanderbiscajin
  • alexanderbiscajin's Avatar Topic Author
I want to disable the add to cart button for specific products and going through the tutorial 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);
}

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
  • Page:
  • 1