I'm trying to add a cart message for a specific shipping class. Adapted from Cart Message for a specific shipping class and a minimal cart total in Woocommerce answer, this is my code attempt:
add_action( 'woocommerce_before_calculate_totals', 'cart_items_shipping_class_message', 20, 1 );
function cart_items_shipping_class_message( $cart ){
if ( is_admin() && ! defined('DOING_AJAX') )
return;
$shipping_class = '150';
// Loop through cart items
foreach( $cart->get_cart() as $cart_item ){
if( $cart_item['data']->get_shipping_class() === $shipping_class ){
wc_clear_notices();
wc_add_notice( sprintf( 'Beers can only be shipped via <a title="Pallet Shiping" href="/shipping-delivery/#Pallet_Shipping" target="_blank" rel="noopener noreferrer">Pallet Shiping</a>. To reveal much cheaper UPS Shipping Rates, remove Beers from the Cart.'), 'notice' );
}
}
}
But it doesn't seem to be working. Any ideas?