function ticket_price($atts) { global $tc; extract(shortcode_atts(array('id' => ''), $atts)); $ticket = new TC_Ticket($id, 'publish'); return apply_filters('tc_cart_currency_and_format', tc_get_ticket_price($ticket->details->ID)); }
function discounted_cart_total($total = false, $discount_code = '') { global $tc, $discount, $discount_value_total, $init_total, $new_total; $cart_subtotal = 0; if (empty($discount)) { $discount = new TC_Discounts(); } if (!$total) { $cart_contents = $tc->get_cart_cookie(); foreach ($cart_contents as $ticket_type => $ordered_count) { $ticket = new TC_Ticket($ticket_type); $cart_subtotal = $cart_subtotal + tc_get_ticket_price($ticket->details->ID) * $ordered_count; } if (!isset($_SESSION)) { session_start(); } $_SESSION['tc_cart_subtotal'] = $cart_subtotal; } $cart_contents = $tc->get_cart_cookie(); $discount_value = 0; $current_date = date("Y-m-d H:i:s"); if ($discount_code == '') { $discount_code = isset($_POST['coupon_code']) ? $_POST['coupon_code'] : ''; } $discount_object = get_page_by_title($discount_code, OBJECT, 'tc_discounts'); if (!empty($discount_object) && $discount_object->post_status == 'publish') { $discount_object = new TC_Discount($discount_object->ID); /* * $discount_object->details->usage_limit */ if (is_numeric(trim($discount_object->id))) { //discount object is not empty means discount code is entered if ($discount_object->details->expiry_date >= $current_date) { $usage_limit = $discount_object->details->usage_limit !== '' ? $discount_object->details->usage_limit : 9999999; //set "unlimited" if empty $number_of_discount_uses = $this->discount_used_times($discount_code); //get real number of discount code uses $discount_codes_available = (int) $usage_limit - (int) $number_of_discount_uses; if ($discount_object->details->discount_availability == '') { //unlimited foreach ($cart_contents as $ticket_type_id => $ordered_count) { $ticket = new TC_Ticket($ticket_type_id); $ticket_price = tc_get_ticket_price($ticket->details->ID); $discount_value_per_each = $discount_object->details->discount_type == 1 ? $discount_object->details->discount_value : $ticket_price / 100 * $discount_object->details->discount_value; $max_discount = $ordered_count >= $discount_codes_available ? $discount_codes_available : $ordered_count; if ($max_discount > 0) { for ($i = 1; $i <= (int) $max_discount; $i++) { $discount_value = $discount_value + $discount_value_per_each; $number_of_discount_uses++; $discount_codes_available = $usage_limit - $number_of_discount_uses; $max_discount = $ordered_count >= $discount_codes_available ? $discount_codes_available : $ordered_count; } } else { $discount->discount_message = __('Discount code invalid or expired', 'tc'); } $i = 1; } //exit; } else { //check ticket marked in availability is in the cart first $is_in_cart = false; foreach ($cart_contents as $ticket_type_id => $ordered_count) { if ($ticket_type_id == $discount_object->details->discount_availability) { $is_in_cart = true; break; } } if ($is_in_cart) { $ticket = new TC_Ticket($discount_object->details->discount_availability); $ticket_price = tc_get_ticket_price($ticket->details->ID); $discount_value_per_each = $discount_object->details->discount_type == 1 ? $discount_object->details->discount_value : $ticket_price / 100 * $discount_object->details->discount_value; $max_discount = $ordered_count >= $discount_codes_available ? $discount_codes_available : $ordered_count; if ($max_discount > 0) { for ($i = 1; $i <= $max_discount; $i++) { $discount_value = $discount_value + $discount_value_per_each; $number_of_discount_uses++; $discount_codes_available = ($discount_object->details->usage_limit == '' ? 99999 : $discount_object->details->usage_limit) - $number_of_discount_uses; $max_discount = $ordered_count >= $discount_codes_available ? $discount_codes_available : $ordered_count; } } else { $discount->discount_message = __('Discount code invalid or expired', 'tc'); } } else { $discount->discount_message = __("Discount code is not valid for the ticket type(s) in the cart.", 'tc'); } } } else { $discount->discount_message = __('Discount code expired', 'tc'); } } } else { $discount->discount_message = __('Discount code cannot be found', 'tc'); } $discount_value_total = $discount_value; add_filter('tc_cart_discount', 'tc_cart_discount_value_total', 10, 0); if (!function_exists('tc_cart_discount_value_total')) { function tc_cart_discount_value_total() { global $discount_value_total; if (!isset($_SESSION)) { session_start(); } $total = $_SESSION['tc_cart_subtotal']; $_SESSION['discount_value_total'] = TC_Discounts::max_discount(tc_minimum_total($discount_value_total), $total); return TC_Discounts::max_discount($discount_value_total, $total); } } $init_total = $total; add_filter('tc_cart_subtotal', 'tc_cart_subtotal_minimum'); if (!function_exists('tc_cart_subtotal_minimum')) { function tc_cart_subtotal_minimum() { global $init_total; if (!isset($_SESSION)) { session_start(); } return tc_minimum_total($_SESSION['tc_cart_subtotal']); } } if (!session_id()) { session_start(); } $new_total = (isset($_SESSION['tc_cart_subtotal']) ? $_SESSION['tc_cart_subtotal'] : 0) - $discount_value; add_filter('tc_cart_total', 'tc_cart_total_minimum_total'); if (!function_exists('tc_cart_total_minimum_total')) { function tc_cart_total_minimum_total() { global $new_total; if (!session_id()) { session_start(); } $_SESSION['tc_cart_total'] = tc_minimum_total($new_total); return tc_minimum_total($new_total); } } if ((int) $new_total == (int) $total || empty($total)) { } else { $discount->discount_message = __('Discount code applied.', 'tc'); $_SESSION['tc_discount_code'] = $discount_code; } if (!isset($_SESSION)) { session_start(); } $_SESSION['discounted_total'] = tc_minimum_total(apply_filters('tc_discounted_total', $new_total)); $discounted_total = $new_total; /* add_filter( 'tc_discounted_fees_total', 'tc_discounted_fees_total' ); if ( !function_exists( 'tc_discounted_fees_total' ) ) { function tc_discounted_fees_total( $fees ) { global $new_total; return $new_total; } } */ //return $discounted_total; }
<?php do_action('tc_cart_col_value_before_quantity', $ticket_type, $ordered_count, tc_get_ticket_price($ticket->details->ID)); ?> <td class="ticket-quantity" class="ticket_quantity"><input class="tickera_button minus" type="button" value="-"><input type="text" name="ticket_quantity[]" value="<?php echo $ordered_count; ?> " class="quantity"> <input class="tickera_button plus" type="button" value="+" /></td> <?php do_action('tc_cart_col_value_before_total_price', $ticket_type, $ordered_count, tc_get_ticket_price($ticket->details->ID)); ?> <td class="ticket-total"><span class="ticket_total"><?php echo apply_filters('tc_cart_currency_and_format', apply_filters('tc_cart_price_per_ticket_and_quantity', tc_get_ticket_price($ticket->details->ID) * $ordered_count, $ticket_type, $ordered_count)); ?> </span></td> <?php do_action('tc_cart_col_value_after_total_price', $ticket_type, $ordered_count, tc_get_ticket_price($ticket->details->ID)); ?> </tr> <?php } ?> <tr class="last-table-row"> <td class="ticket-total-all" colspan="<?php echo apply_filters('tc_cart_table_colspan', '5'); ?> "> <?php do_action('tc_cart_col_value_before_total_price_subtotal', apply_filters('tc_cart_subtotal', $cart_subtotal)); ?> <span class="total_item_title"><?php _e('SUBTOTAL: ', 'tc');
function widget($args, $instance) { global $tc; $cart_url = trailingslashit($tc->get_cart_slug(true)); $show_widget_on_cart_page = apply_filters('tc_show_cart_widget_on_cart_page', false); if (tc_current_url() !== $cart_url || $show_widget_on_cart_page) { extract($args, EXTR_SKIP); echo $before_widget; $title = empty($instance['title']) ? ' ' : apply_filters('tc_cart_widget_title', $instance['title']); $button_title = empty($instance['button_title']) ? '' : apply_filters('tc_cart_widget_button_title', $instance['button_title']); if (!empty($title)) { echo $before_title . $title . $after_title; } ?> <?php // Cart Contents $cart_contents = $tc->get_cart_cookie(); if (!empty($cart_contents)) { do_action('tc_cart_before_ul', $cart_contents); ?> <ul class='tc_cart_ul'> <?php foreach ($cart_contents as $ticket_type => $ordered_count) { $ticket = new TC_Ticket($ticket_type); ?> <li id='tc_ticket_type_<?php echo $ticket_type; ?> '> <?php echo apply_filters('tc_cart_widget_item', $ordered_count . ' x ' . $ticket->details->post_title . ' (' . apply_filters('tc_cart_currency_and_format', tc_get_ticket_price($ticket->details->ID) * $ordered_count) . ')', $ordered_count, $ticket->details->post_title, tc_get_ticket_price($ticket->details->ID)); ?> </li> <?php } ?> </ul><!--tc_cart_ul--> <?php do_action('tc_cart_after_ul', $cart_contents); } else { do_action('tc_cart_before_empty'); ?> <span class='tc_empty_cart'><?php _e('The cart is empty', 'tc'); ?> </span> <?php do_action('tc_cart_after_empty'); } ?> <button class='tc_widget_cart_button' data-url='<?php echo esc_attr($cart_url); ?> '><?php echo $button_title; ?> </button> <div class='tc-clearfix'></div> <?php echo $after_widget; } }
function update_cart_widget() { $cart_contents = $this->get_cart_cookie(); if (!empty($cart_contents)) { do_action('tc_cart_before_ul', $cart_contents); ?> <ul class='tc_cart_ul'> <?php foreach ($cart_contents as $ticket_type => $ordered_count) { $ticket = new TC_Ticket($ticket_type); ?> <li id='tc_ticket_type_<?php echo $ticket_type; ?> '> <?php echo apply_filters('tc_cart_widget_item', $ordered_count . ' x ' . $ticket->details->post_title . ' (' . apply_filters('tc_cart_currency_and_format', tc_get_ticket_price($ticket->details->ID) * $ordered_count) . ')', $ordered_count, $ticket->details->post_title, tc_get_ticket_price($ticket->details->ID)); ?> </li> <?php } ?> </ul><!--tc_cart_ul--> <?php do_action('tc_cart_after_ul', $cart_contents); } else { do_action('tc_cart_before_empty'); ?> <span class='tc_empty_cart'><?php _e('The cart is empty', 'tc'); ?> </span> <?php do_action('tc_cart_after_empty'); } exit; }