function __construct($id = '', $output = 'OBJECT') { $this->id = $id; $this->output = $output; $this->details = get_post($this->id, $this->output); $discounts = new TC_Discounts(); $fields = $discounts->get_discount_fields(); foreach ($fields as $field) { if (!isset($this->details->{$field['field_name']})) { $this->details->{$field['field_name']} = get_post_meta($this->id, $field['field_name'], true); } } }
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); }
function tc_order_field_value($order_id, $value, $meta_key, $field_type, $field_id = false) { global $tc; if ($field_type == 'order_status') { $new_value = str_replace('_', ' ', $value); if ($value == 'order_fraud') { $color = "red"; } else { if ($value == 'order_received') { $color = "#ff6600"; //yellow } else { if ($value == 'order_paid') { $color = "green"; } else { $color = "black"; } } } return sprintf(__('%1$s %2$s %3$s', 'tc'), '<font color="' . $color . '">', __(ucwords($new_value), 'tc'), '</font>'); } else { if ($field_id == 'order_date') { return tc_format_date($value); //date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $value, false ); } else { if ($field_id == 'customer') { $order = new TC_Order($order_id); $author_id = $order->details->post_author; if (!user_can($author_id, 'manage_options') && $author_id != 0) { $buyer_info = '<a href="' . admin_url('user-edit.php?user_id=' . $author_id) . '">' . $value['buyer_data']['first_name_post_meta'] . ' ' . $value['buyer_data']['last_name_post_meta'] . '</a>'; } else { $buyer_info = $value['buyer_data']['first_name_post_meta'] . ' ' . $value['buyer_data']['last_name_post_meta']; } return $buyer_info; } elseif ($field_id == 'parent_event') { $events = $tc->get_cart_events($value); foreach ($events as $event_id) { $event = new TC_Event($event_id); echo '<a href="post.php?post=' . $event->details->ID . '&action=edit">' . $event->details->post_title . '</a> x ' . $tc->get_cart_event_tickets($value, $event->details->ID) . '<br />'; } } elseif ($field_id == 'gateway') { return $value['gateway']; } elseif ($field_id == 'gateway_admin_name') { return $value['gateway_admin_name']; } elseif ($field_id == 'discount') { $discounts = new TC_Discounts(); $discount_total = $discounts->get_discount_total_by_order($order_id); $discount_object = get_page_by_title($value['coupon_code'], OBJECT, 'tc_discounts'); if ($discount_total > 0) { $discount_total = apply_filters('tc_cart_currency_and_format', $discount_total) . '<br />' . __('Code: ', 'tc') . '<a href="edit.php?post_type=tc_events&page=tc_discount_codes&action=edit&ID=' . $discount_object->ID . '">' . $value['coupon_code'] . '</a>'; } else { $discount_total = '-'; } return $discount_total; } elseif ($field_id == 'total') { return apply_filters('tc_cart_currency_and_format', $value['total']); } elseif ($field_id == 'subtotal') { return apply_filters('tc_cart_currency_and_format', $value['subtotal']); } elseif ($field_id == 'subtotal') { return apply_filters('tc_cart_currency_and_format', $value['subtotal']); } elseif ($field_id == 'fees_total') { return apply_filters('tc_cart_currency_and_format', $value['fees_total']); } elseif ($field_id == 'tax_total') { return apply_filters('tc_cart_currency_and_format', $value['tax_total']); } else { return $value; } } } }
function update_cart() { global $tc_cart_errors; $cart_error_number = 0; $required_fields_error_count = 0; if (isset($_POST['cart_action']) && $_POST['cart_action'] == 'update_cart' || isset($_POST['cart_action']) && $_POST['cart_action'] == 'apply_coupon' || isset($_POST['cart_action']) && $_POST['cart_action'] == 'proceed_to_checkout') { $discount = new TC_Discounts(); $discount->discounted_cart_total($_SESSION['cart_subtotal_pre']); $cart = array(); $ticket_type_count = 0; $ticket_quantity = $_POST['ticket_quantity']; if (isset($_POST['cart_action'])) { if ($_POST['cart_action'] == 'update_cart' || $_POST['cart_action'] == 'proceed_to_checkout') { $tc_cart_errors .= '<ul>'; foreach ($_POST['ticket_cart_id'] as $ticket_id) { $ticket = new TC_Ticket($ticket_id); if ($ticket_quantity[$ticket_type_count] <= 0) { unset($cart[$ticket_id]); //remove from cart } else { if ($ticket->details->min_tickets_per_order != 0 && $ticket->details->min_tickets_per_order !== '') { if ($ticket_quantity[$ticket_type_count] < $ticket->details->min_tickets_per_order) { $cart[$ticket_id] = (int) $ticket->details->min_tickets_per_order; $ticket_quantity[$ticket_type_count] = (int) $ticket->details->min_tickets_per_order; $tc_cart_errors .= '<li>' . sprintf(__('Minimum order quantity for "%s" is %d', 'tc'), $ticket->details->post_title, $ticket->details->min_tickets_per_order) . '</li>'; $cart_error_number++; } } if ($ticket->details->max_tickets_per_order != 0 && $ticket->details->max_tickets_per_order !== '') { if ($ticket_quantity[$ticket_type_count] > $ticket->details->max_tickets_per_order) { $cart[$ticket_id] = (int) $ticket->details->max_tickets_per_order; $ticket_quantity[$ticket_type_count] = (int) $ticket->details->max_tickets_per_order; $tc_cart_errors .= '<li>' . sprintf(__('Maximum order quantity for "%s" is %d', 'tc'), $ticket->details->post_title, $ticket->details->max_tickets_per_order) . '</li>'; $cart_error_number++; } } $quantity_left = $ticket->get_tickets_quantity_left(); if ($quantity_left >= $ticket_quantity[$ticket_type_count]) { $cart[$ticket_id] = (int) $ticket_quantity[$ticket_type_count]; } else { if ($quantity_left > 0) { $tc_cart_errors .= '<li>' . sprintf(__('Only %d "%s" %s left', 'tc'), $quantity_left, $ticket->details->post_title, $quantity_left > 1 ? __('tickets', 'tc') : __('ticket', 'tc')) . '</li>'; $cart_error_number++; } else { $tc_cart_errors .= '<li>' . sprintf(__('"%s" tickets are sold out', 'tc'), $ticket->details->post_title) . '</li>'; $cart_error_number++; } $cart[$ticket_id] = (int) $quantity_left; } } $ticket_type_count++; } $tc_cart_errors .= '</ul>'; add_filter('tc_cart_errors', array(&$this, 'tc_cart_errors'), 10, 1); $this->update_discount_code_cookie($_POST['coupon_code']); $this->update_cart_cookie($cart); $cart_contents = $this->get_cart_cookie(); $discount = new TC_Discounts(); $discount->discounted_cart_total(); if (empty($cart)) { $this->remove_order_session_data(false); } } if ($_POST['cart_action'] == 'apply_coupon') { $discount = new TC_Discounts(); $discount->discounted_cart_total(); add_filter('tc_discount_code_message', array('TC_Discounts', 'discount_code_message'), 11, 1); } if ($_POST['cart_action'] == 'proceed_to_checkout') { $required_fields = $_POST['tc_cart_required']; //array of required field names foreach ($_POST as $key => $value) { if ($key !== 'tc_cart_required') { if (in_array($key, $required_fields)) { if (!is_array($value)) { if (trim($value) == '') { $required_fields_error_count++; } } else { foreach ($_POST[$key] as $val) { if (!is_array($val)) { if (trim($val) == '') { $required_fields_error_count++; } } else { foreach ($val as $val_str) { if (trim($val_str) == '') { $required_fields_error_count++; } } } } } } } } if ($required_fields_error_count > 0) { $tc_cart_errors .= '<li>' . __('All fields marked with * are required.', 'tc') . '</li>'; } if ($cart_error_number == 0 && $required_fields_error_count == 0) { $this->save_cart_post_data(); do_action('tc_cart_passed_successfully'); wp_redirect($this->get_payment_slug(true)); exit; } } } } }
<?php $discounts = new TC_Discounts(); $page = $_GET['page']; if (isset($_POST['add_new_discount'])) { if (check_admin_referer('save_discount')) { if (current_user_can('manage_options') || current_user_can('add_discount_cap')) { $discounts->add_new_discount(); $message = __('Discount Code data has been saved successfully.', 'tc'); } else { $message = __('You do not have required permissions for this action.', 'tc'); } } } if (isset($_GET['action']) && $_GET['action'] == 'edit') { $discount = new TC_Discount($_GET['ID']); $post_id = (int) $_GET['ID']; } if (isset($_GET['action']) && $_GET['action'] == 'delete') { if (!isset($_POST['_wpnonce'])) { check_admin_referer('delete_' . $_GET['ID']); if (current_user_can('manage_options') || current_user_can('delete_discount_cap')) { $discount = new TC_Discount((int) $_GET['ID']); $discount->delete_discount(); $message = __('Discount Code has been successfully deleted.', 'tc'); } else { $message = __('You do not have required permissions for this action.', 'tc'); } } } if (isset($_GET['page_num'])) {
function tc_get_order_discount_info($field_name = '', $post_id = '') { $discounts = new TC_Discounts(); $discount_total = $discounts->get_discount_total_by_order($post_id); if ($discount_total > 0) { $discount_total = apply_filters('tc_cart_currency_and_format', $discount_total); } else { $discount_total = '-'; } echo $discount_total; }