public function today_menu() { $data = array('can_order_today' => can_order_today(), 'menu' => array(), 'aguas' => array(), 'postres' => array(), 'sides' => array()); error_log(can_order_today()); $dia = date('Y-m-d'); if (!can_order_today()) { DABBA_API_Output::get()->output(true, 200, '', $data); } $product_args = array('post_type' => 'product', 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_fecha_menu_meta', 'value' => $dia))); if (can_order_breakfast() && has_breakfast()) { $product_args['tax_query'] = array(array('taxonomy' => 'comida-del-dia', 'field' => 'slug', 'terms' => 'desayuno')); } else { if (can_order_lunch() && has_lunch()) { $product_args['tax_query'] = array(array('taxonomy' => 'comida-del-dia', 'field' => 'slug', 'terms' => 'comida')); } else { if (can_order_dinner() && has_dinner()) { $product_args['tax_query'] = array(array('taxonomy' => 'comida-del-dia', 'field' => 'slug', 'terms' => 'cena')); } } } $query = new WP_Query($product_args); while ($query->have_posts()) { if ($query->have_posts()) { $query->the_post(); global $product; global $post; $image_ids = $product->get_gallery_attachment_ids(); $image = wp_get_attachment_url($image_ids[0]); $horizontal_image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full'); if (!$image) { $image = $horizontal_image; } $carTemp = get_the_terms($post->ID, 'caracteristica-platillo'); $caracteristicas_platillo = array(); if (!empty($carTemp)) { foreach ($carTemp as $caracteristica) { $caracteristicas_platillo[] = array('icon' => THEMEPATH . "icons/" . $caracteristica->slug . ".svg", 'name' => $caracteristica->name); } } $ingredientes = get_ingredientes($post->ID); $guarnicion_1 = get_post_meta($post->ID, '_guarnicion_1_meta', true); $guarnicion_2 = get_post_meta($post->ID, '_guarnicion_2_meta', true); $porcion = get_post_meta($post->ID, '_porcion_meta', true); $proteina = get_post_meta($post->ID, '_proteina_meta', true); $calorias = get_post_meta($post->ID, '_calorias_meta', true); $fibra_dietetica = get_post_meta($post->ID, '_fibra_dietetica_meta', true); $menu = array('id' => get_the_ID(), 'title' => html_entity_decode(get_the_title()), 'descripcion' => format_contenido_platillo($guarnicion_1, $guarnicion_2), 'content' => get_the_content(), 'image' => $image, 'horizontal_image' => $horizontal_image[0], 'guarnicion_1' => $guarnicion_1, 'guarnicion_2' => $guarnicion_2, 'caracteristicas_platillo' => $caracteristicas_platillo, 'ingredientes' => $ingredientes, 'porcion' => $porcion, 'proteina' => $proteina, 'calorias' => $calorias, 'fibra_dietetica' => $fibra_dietetica, 'price' => $product->get_price(), 'stock' => $product->get_stock_quantity(), 'is_in_stock' => $product->is_in_stock(), 'menu_date' => $dia); $data['menu'][] = $menu; } } $data['aguas'] = $this->get_additional_items('agua', 4); $data['postres'] = $this->get_additional_items('postre', 4); $data['sides'] = $this->get_additional_items('complemento', 4); DABBA_API_Output::get()->output(true, 200, '', $data); }
/** * Regresa si se pueden comprar comidas * dependiendo de la hora del día * @return boolean */ function can_order_lunch() { if (!has_lunch()) { return 0; } if (6 == date('N') || 7 == date('N')) { return 0; } $time_now = date("Y-m-d h:i:sa"); $last_timeframe = mktime(16, 45, 0, date("m"), date("d"), date("Y")); $diff_last_timeframe = round(($last_timeframe - strtotime($time_now)) / 60, 2); if (15 <= $diff_last_timeframe) { return 1; } return 0; }