Bug found (with solution)
-
Hi. I found a bug where the plugin removes the cart button for all the categories created prior to installation.
The solution should be where the code reads:
/**
* Appling Filter on single product page
* @global type $product
*/
if (!function_exists(‘wpiudacb_user_filter_addtocart_for_single_product_page’)) {function wpiudacb_user_filter_addtocart_for_single_product_page() {
global $product;
global $post;
$terms = get_the_terms($product->id, ‘product_cat’);
$cat_option = ‘default’;
$cat_inquire_us_link = ”;
if (!empty($terms)) {
foreach ($terms as $cat) {
if (get_option(“wpiudacb_category_disable_add_to_cart_$cat->term_id”) != ‘Default’) {
$cat_option = get_option(“wpiudacb_category_disable_add_to_cart_$cat->term_id”);
$cat_inquire_us_link = get_option(“wpiudacb_inqure_us_link_$cat->term_id”);
}
}
}
if ($cat_option != ‘default’) {
remove_action(‘woocommerce_single_product_summary’, ‘woocommerce_template_single_add_to_cart’, 30);it should be:
/**
* Appling Filter on single product page
* @global type $product
*/
if (!function_exists(‘wpiudacb_user_filter_addtocart_for_single_product_page’)) {function wpiudacb_user_filter_addtocart_for_single_product_page() {
global $product;
global $post;
$terms = get_the_terms($product->id, ‘product_cat’);
$cat_option = ‘default’;
$cat_inquire_us_link = ”;
if (!empty($terms)) {
foreach ($terms as $cat) {
if (get_option(“wpiudacb_category_disable_add_to_cart_$cat->term_id”) != ‘Default’) {
$cat_option = get_option(“wpiudacb_category_disable_add_to_cart_$cat->term_id”);
$cat_inquire_us_link = get_option(“wpiudacb_inqure_us_link_$cat->term_id”);
}
}
}
if (($cat_option != false ) && ($cat_option != ‘default’)) {
add_filter( ‘woocommerce_is_purchasable’, false );This is because the options on those categories are not set. I also took the liberty of replacing remove_action(‘woocommerce_single_product_summary’, ‘woocommerce_template_single_add_to_cart’, 30); with add_filter( ‘woocommerce_is_purchasable’, false ); that i think is more clean.
- The topic ‘Bug found (with solution)’ is closed to new replies.