function discount_when_room_winter_in_cart() { global $woocommerce; $cart = $woocommerce->cart->get_cart(); $_pf = new WC_Product_Factory(); foreach ($cart as $item) { $_product = $_pf->get_product($item['product_id']); if (TauchTerminal_Tulamben::isRoomProduct($_product->get_sku())) { $winderDays = 0; $start = strtotime($item['start_date']); $end = strtotime($item['end_date']); $threemonths = strtotime("+3 months", strtotime(date('Y-m-d'))); $wstart = strtotime(TauchTerminal_DB::getTTOption('winter_start')); $wend = strtotime(TauchTerminal_DB::getTTOption('winter_end')); if ($start >= $wstart && $end <= $wend) { $winderDays += floor(($end - $start) / (60 * 60 * 24)); // var_dump('all days'); } else { if ($start >= $wstart) { $winderDays += floor(($wend - $start) / (60 * 60 * 24)); // var_dump('start in season'); } else { if ($end <= $wend) { $winderDays += floor(($end - $wstart) / (60 * 60 * 24)); // var_dump('End in season'); } } } if ($winderDays != 0) { $title = 'Winter Season' . "\n" . $winderDays . ' Day'; if ($winderDays > 1) { $title .= 's'; } $discount = floatval(TauchTerminal_DB::getTTOption('winter_discount')) * $winderDays * -1; $woocommerce->cart->add_fee($title, $discount, true, ''); // Early bird if ($start >= $threemonths) { $_product = new WC_Product_Variation($item['variation_id']); $discountP = floatval(TauchTerminal_DB::getTTOption('earlybird')); $price = floatval(preg_replace('#[^\\d.]#', '', $woocommerce->cart->get_product_price($_product))); $discount = $price * $discountP / 100 * $winderDays * -1; $title = 'Earlybird ' . $discountP . '%' . "\n" . 'for ' . $winderDays . ' Day'; if ($winderDays > 1) { $title .= 's'; } $woocommerce->cart->add_fee($title, $discount, true, ''); } } } } }
public static function addCustomDataToProduct($cart_item_data, $product_id, $variation_id) { global $woocommerce; $_pf = new WC_Product_Factory(); $data = $_POST; // Split all the products added to the cart $unique_cart_item_key = md5(microtime() . rand() . "Hi Mom!"); $cart_item_data['unique_key'] = $unique_cart_item_key; $product = $_pf->get_product($product_id); if (TauchTerminal_Tulamben::isRoomProduct($product->get_sku())) { $cart_item_data['start_date'] = $data['start']; $cart_item_data['end_date'] = $data['end']; $attributes = $product->get_attributes(); if ($data['quantity-person']) { $cart_item_data['persons'] = $data['quantity-person']; } if ($data['attribute_bed']) { $labels = self::getAttributeLabel($attributes, 'attribute_bed', $data['attribute_bed']); $name = $labels['name']; $cart_item_data['ttt_meta'][$name] = $labels['value']; } if ($data['attribute_special-requests']) { $labels = self::getAttributeLabel($attributes, 'attribute_special-requests', $data['attribute_special-requests']); $name = $labels['name']; $cart_item_data['ttt_meta'][$name] = $labels['value']; } } return $cart_item_data; }
if (wc_product_sku_enabled() && ($product->get_sku() || $product->is_type('variable'))) { ?> <span class="sku_wrapper hidden"><?php _e('SKU:', 'woocommerce'); ?> <span class="sku" itemprop="sku"><?php echo ($sku = $product->get_sku()) ? $sku : __('N/A', 'woocommerce'); ?> </span></span> <input type="hidden" name="isFamily" value="<?php echo TauchTerminal_Tulamben::getProductTypeBySKU($sku) == 'family'; ?> "> <input type="hidden" name="isBungalow" value="<?php echo TauchTerminal_Tulamben::getProductTypeBySKU($sku) == 'bungalow'; ?> "> <?php } ?> <?php echo $product->get_categories(', ', '<span class="posted_in">' . _n('Category:', 'Categories:', $cat_count, 'woocommerce') . ' ', '</span>'); ?> <?php echo $product->get_tags(', ', '<span class="tagged_as">' . _n('Tag:', 'Tags:', $tag_count, 'woocommerce') . ' ', '</span>'); ?>
// Meta data if ($cart_item['start_date'] && $cart_item['end_date']) { ?> <dl class="variation"> <dt class="variation-<?php echo sanitize_html_class('Travel dates'); ?> "><?php echo wp_kses_post(__('Travel dates')); ?> :</dt> <dd class="variation-<?php echo sanitize_html_class('Travel dates'); ?> "><?php echo TauchTerminal_Tulamben::formatDateFromTo($cart_item['start_date'], $cart_item['end_date']); ?> </dd> </dl> <?php } if (isset($cart_item['ttt_meta'])) { foreach ($cart_item['ttt_meta'] as $name => $value) { if ($value) { ?> <dl class="variation"> <dt class="variation-<?php echo sanitize_html_class($name); ?> "><?php echo wp_kses_post($name);
" /> <?php } else { ?> <input type="text" class="form-control start-date" name="start" /> <span class="input-group-addon">to</span> <input type="text" class="form-control end-date" name="end" /> <?php } ?> </div> <?php if (count($dates) == 0) { ?> <p class="help-block"><?php printf(__('Please give us an idea when you are staying in Bali so we can organize your %s. We suggest to start by booking a room first.', 'tauchterminal'), TauchTerminal_Tulamben::getProductTypeBySKU($product->get_sku())); ?> </p> <?php } else { ?> <p class="help-block"><?php echo __('You already selected your dates.', 'tauchterminal'); ?> </p> <?php } ?> </div> </div> <?php
function booking_handler() { TauchTerminal_Tulamben::hotelbooking_handler(); }
?> </p> </div> </div> <div class="form-group"> <label for="quantity-person" class="col-sm-3 control-label"><?php echo __('Persons', 'tauchterminal'); ?> </label> <div class="col-sm-9"> <?php $max_value = apply_filters('woocommerce_quantity_input_max', $product->backorders_allowed() ? '' : $product->get_stock_quantity(), $product); if (!$max_value && TauchTerminal_Tulamben::isRoomProduct($product->get_sku())) { if (TauchTerminal_Tulamben::getProductTypeBySKU($product->get_sku()) == 'family') { $max_value = 5; } elseif (TauchTerminal_Tulamben::getProductTypeBySKU($product->get_sku()) == 'deluxe') { $max_value = 3; } else { $max_value = 2; } } woocommerce_quantity_input(array('input_name' => 'quantity-person', 'min_value' => apply_filters('woocommerce_quantity_input_min', 1, $product), 'max_value' => apply_filters('woocommerce_quantity_input_max', $product->backorders_allowed() ? '' : $product->get_stock_quantity(), $product), 'input_value' => isset($_POST['quantity-person']) ? wc_stock_amount($_POST['quantity-person']) : 1)); ?> </div> </div> <?php // var_dump($product->get_attributes()); wc_get_template('single-product-rooms/add-to-cart/attributes.php', array('attributes' => $product->get_attributes())); // Enqueue variation scripts wp_enqueue_script('wc-add-to-cart-variation'); wc_get_template('single-product-rooms/add-to-cart/variable.php', array('available_variations' => $available_variations, 'attributes' => $product->get_variation_attributes(), 'selected_attributes' => $product->get_variation_default_attributes()));
</td> <td class="product-price"> <?php echo apply_filters('woocommerce_cart_item_price', WC()->cart->get_product_price($_product), $cart_item, $cart_item_key); ?> </td> <td class="product-quantity"> <?php if ($_product->is_sold_individually()) { $product_quantity = sprintf('1 <input type="hidden" name="cart[%s][qty]" value="1" />', $cart_item_key); } else { $product_quantity = woocommerce_quantity_input(array('input_name' => "cart[{$cart_item_key}][qty]", 'input_value' => $cart_item['quantity'], 'max_value' => $_product->backorders_allowed() ? '' : $_product->get_stock_quantity(), 'min_value' => '0'), $_product, false); } if (TauchTerminal_Tulamben::isRoomProduct($_product->get_sku())) { if ($cart_item['quantity'] > 1) { printf(__('%s Nights'), $cart_item['quantity']); } else { echo __('1 Night'); } } else { echo apply_filters('woocommerce_cart_item_quantity', $product_quantity, $cart_item_key); } ?> </td> <td class="product-subtotal"> <?php echo apply_filters('woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal($_product, $cart_item['quantity']), $cart_item, $cart_item_key); ?>
public static function addCustomDataToOrderAdmin($item_id, $item, $_product) { global $woocommerce; if (isset($item['TauchTerminal'])) { $_pf = new WC_Product_Factory(); $data = unserialize($item['TauchTerminal']); ?> <table cellspacing="0" class="display_meta"> <tbody> <?php if (isset($data['start_date']) && isset($data['end_date'])) { ?> <tr> <th><?php echo wp_kses_post(__('Travel dates')); ?> :</th> <td><?php echo TauchTerminal_Tulamben::formatDateFromTo($data['start_date'], $data['end_date']); ?> </td> </tr> <?php } if (isset($data['persons'])) { ?> <tr> <th><?php echo wp_kses_post(__('Persons')); ?> :</th> <td><?php echo $data['persons']; ?> </td> </tr> <?php } ?> </tbody> </table> <?php } }