public function get_booking_dates($product, $adjust_items_from_shopping_cart = false) { $state_key = $this->make_product_state_key('validbookingdates', $product) . ($adjust_items_from_shopping_cart ? '_1' : '_0'); $result = $this->get_state($state_key, false); if (false === $result) { $result = adventure_touts_get_tour_booking_dates($product->id); if ($adjust_items_from_shopping_cart) { $current_id = $product->id; $deduct = array(); // deduct items that already added to shopping cart $cart_items = WC()->cart->get_cart(); if ($cart_items) { foreach ($cart_items as $item) { if ($item['product_id'] == $current_id && isset($item['date'])) { $quantity = isset($item['quantity']) ? $item['quantity'] : 0; if (isset($deduct[$item['date']])) { $deduct[$item['date']] += $quantity; } else { $deduct[$item['date']] = $quantity; } } } if ($deduct) { foreach ($deduct as $date => $quantity) { if (isset($result[$date])) { $result[$date] -= $quantity; if ($result[$date] < 1) { unset($result[$date]); } } } } } } $this->set_state($state_key, $result); } return $result; }
/** * Tour details page, tabs filter function. * Defines what tabs should be rendered. * * @return void */ function adventure_tours_filter_tour_tabs($tabs) { global $product; if (empty($product)) { return $tabs; } $tabs['description'] = array('title' => esc_html__('Details', 'adventure-tours'), 'priority' => 10, 'top_section_callback' => 'adventure_tours_render_tab_description_top_section', 'callback' => 'adventure_tours_render_tab_description'); $additionalTabs = vp_metabox('tour_tabs_meta.tabs'); if ($additionalTabs) { foreach ($additionalTabs as $key => $tabFields) { $tabContent = apply_filters('the_content', $tabFields['content']); if ($tabContent) { $tabs['atab' . $key] = array('title' => esc_html($tabFields['title']), 'content' => $tabContent); } } } // Photos tab rendering. ob_start(); adventure_tours_render_tab_photos(); $photosTabContent = ob_get_clean(); if ($photosTabContent) { $tabs['photos'] = array('title' => esc_html__('Photos', 'adventure-tours'), 'priority' => 25, 'content' => $photosTabContent); } /* if ( comments_open() ) { $tabs['reviews'] = array( 'title' => sprintf( esc_html__( 'Reviews (%d)', 'adventure-tours' ), $product->get_review_count() ), 'priority' => 30, 'callback' => 'comments_template', ); }*/ $booking_dates = adventure_touts_get_tour_booking_dates($product->id); if ($booking_dates) { $tabs['booking_form'] = array('title' => apply_filters('adventure_tours_booking_form_title', esc_html__('Book the tour', 'adventure-tours'), $product), 'tab_css_class' => 'visible-xs booking-form-scroller', 'priority' => 35, 'content' => ''); } return $tabs; }