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; }
</div> <p class="help-block"><?php echo __('By default the range is set to 6 nights.', 'tauchterminal'); ?> </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()));
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, ''); } } } } }
</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); ?>