Add custom class to cart items in WooCommerce Blocks Cart page

I need to add a custom class to cart items for the specific products in WooCommerce cart page. I am using Cart Blocks. Based on Add CSS class(es) to WooCommerce cart items with (or based on) product categories answer code, here is my code attempt: // Add class to grouped items in the cart function add_grouped_items_class_to_cart_item($class, $cart_item, $cart_item_key) { // Check if the item is a grouped product if (isset($cart_item['data']) && $cart_item['data']->is_type('wooco')) { $product = $cart_item['data']; $product_type = $product->get_type(); $product_ids = array(); $metadata = $product->get_meta_data(); $data_array = $metadata[0]->get_data(); $linked_items = $data_array['value']; $items = explode(',', $linked_items); foreach ($items as $item) { //$parts = explode('/', $item); //$product_ids[]= $parts[0]; $class= 'wooco_item'; } } return $class; } add_filter('woocommerce_cart_item_class', 'add_grouped_items_class_to_cart_item', 10, 3); But the code hasn't worked at all and no custom class has added to the products After I asked ChatGPT and many AI bots (as Copilot, Gemini, Claude ...), they unanimously agree that this code must be used for Legacy WooCommerce cart page, but I am using Cart Blocks on cart page, so I should have to use JavaScript to get what I need. But I can't use JavaScript here at all, because it must use Ajax and PHP to detect the type of the product based on its ID, then add the required custom class and this takes a period of time. Here is the structure of my cart page : <table class="wc-block-cart-items wp-block-woocommerce-cart-line-items-block" tabindex="-1"> <thead> <tr class="wc-block-cart-items__header"> <th class="wc-block-cart-items__header-image"><span>Product</span></th> <th class="wc-block-cart-items__header-product"><span>Details</span></th> <th class="wc-block-cart-items__header-total"><span>Total</span></th> </tr> </thead> <tbody> <tr class="wc-block-cart-items__row" tabindex="-1"> <!-- the rest data --> </tr> </tbody> </table> How can I to add a custom class to cart items in WooCommerce Blocks Cart page, for specific products?

Comment (0)

You’ll be in good company