Wordpress LScache Plugin: Caching Woocommerce product pages
Last Updated on: Wed, 15 Apr 2026 00:00:02 Hi, We are using the following function to add a body class to Woocommerce product pages if the visitor has already added the product into the cart. Then we display different buttons using CSS. The issue is since Litespeed cache the product pages this function does not execute when a product is added to the cart. I am wondering if there is a solution for this while still caching the product pages? `/ Add body class if the product already in cart / function ywp_check_product_is_in_cart( $product_id ) if ( ! WC()->cart->is_empty() ) foreach( WC()->cart->get_cart() as $cart_item ) $cart_item_ids = array( $cart_item[product_id], $cart_item[variation_id] ) if( in_array( $product_id, $cart_item_ids ) ) return true return false return false add_filter( body_class, ywp_body_class_for_cart_items ) function ywp_body_class_for_cart_items( $classes ) // Check user currently is in product page if( ! is_singular( product ) ) return $classes if( ywp_check_product_is_in_cart( get_the_id() ) ) $classes[] = cart-has-item return $classes Hi, If this can happen on any of your product page, then please consider to use ESI block more information here https://docs.litespeedtech.com/lscache/lscwp/api/#generate-esi-block-url Best regards,
LiteCache Rush: Speed comes from using less, not from doing it faster
Reference