Ver producto reservable en carrito con Woocommece Booking
Con esta pequeña función PHP podemos saber si tenemos en el carrito de WC algún producto reservable de Woocommerce Booking.
Editado
// Ver si el carrito tiene un producto reservable
function wc_carrito_tiene_reserva() {
if ( ! function_exists('WC') || ! WC()->cart ) {
return false;
}
foreach ( WC()->cart->get_cart() as $item ) {
if ( isset($item['data']) && method_exists($item['data'], 'get_type') ) {
if ( $item['data']->get_type() === 'booking' ) {
return true;
}
}
}
return false;
}
if( wc_carrito_tiene_reserva ) echo 'Hay productos reservables en carrito!';Como podemos intuir, si se cumple la condicional devuelve true, si no false.Editado
0
Puntos
Puntos
40
Visitas
Visitas
0
Resp
Resp
Por alber hace 2 semanas
Admin