Welcome,
Guest
|
TOPIC:
I am trying to disable add to cart button 22 Feb 2018 11:11 #1
|
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!
Welcome,
Guest
|
|
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); } |
|
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);
} 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);
} Best regards, Reinhold |