# 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;
}

Maybe because you haven’t checked for
if ( is_admin() ) { … }
To prevent this code running in the backend.
If you’re going to be writing code, you need to have debugging turned on to see the error https://wordpress.org/support/article/debugging-in-wordpress/