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.
// 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
40
Visitas
0
Resp
Por alber hace 2 semanas
Admin
Para comentar Inicia sesión o Regístrate
Phpres 2025@ All rights reserved.
Utilizamos cookies para mejorar la navegación en el sitio. Más información Aceptar