Pages tab show this error “There has been a critical error on this website”

[ad_1]

# When I run this code snippet, the Pages tab show this error “There has been a critical error on this website. Please check your site admin email inbox for instructions. ” I figured out that there was something wrong in the foreach loop. What might be the issue.

add_filter(‘post_class’, ‘wp_disable_cart’, 10,3);
function wp_disable_cart($classes, $class, $product_id) {
$categories = array(‘meeting-room’);
$has_category = false;
// Loop through cart items
/* foreach ( WC()->cart->get_cart() as $cart_item ) {
// Check for product categories
if ( has_term( $categories, ‘product_cat’, $cart_item[‘product_id’] ) ) {
$has_category = true;
break;
}
}*/
// Disable button has category and none meeting room category
if ( $has_category ) {
global $product;
if ( ! has_term( $categories, ‘product_cat’, $product->get_id() ) ) {
$classes = array_merge([‘disable-button’], $classes);
}
}
return $classes;
}

[ad_2]
2 Comments
  1. Maybe because you haven’t checked for

    if ( is_admin() ) { … }

    To prevent this code running in the backend.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer