I would like to set a message to specific shipping class in Woocommerce checkout page.
I tried using:
add_action( 'woocommerce_review_order_before_order_total', 'cart_items_shipping_class_message', 20, 1 );
function cart_items_shipping_class_message( $cart ){
$shipping_class_id = 14; // Your shipping class Id
// Loop through cart items
foreach( WC()->cart->get_cart() as $cart_item ){
// Check cart items for specific shipping class, displaying a notice
//if( $cart_item['data']->get_shipping_class_id() == $shipping_class_id ){
var_dump($cart_item['data']->get_shipping_class_id());
echo "Do poznámky k objednávce napište adresu Zásilkovny nebo ZBoxu, kam chcete objednávku doručit.";
//break;
//}
}
}
But when I try to var_dump
selected shipping class, it always returns me int(0)
.
I have used something similar to: Cart Message for a Specific Shipping Class in WooCommerce, because It did not work for me.