コード例 #1
0
function tc_quantity_selector($ticket_id)
{
    $quantity = 10;
    $ticket = new TC_Ticket($ticket_id);
    $quantity_left = $ticket->get_tickets_quantity_left();
    $max_quantity = get_post_meta($ticket_id, 'max_tickets_per_order', true);
    if (isset($max_quantity) && is_numeric($max_quantity)) {
        $quantity = $max_quantity;
    }
    if ($quantity_left <= $quantity) {
        $quantity = $quantity_left;
    }
    $min_quantity = get_post_meta($ticket_id, 'min_tickets_per_order', true);
    if (isset($min_quantity) && is_numeric($min_quantity) && $min_quantity <= $quantity) {
        $i_val = $min_quantity;
    } else {
        $i_val = 1;
    }
    if ($quantity_left > 0) {
        ?>
		<select class="tc_quantity_selector">
			<?php 
        for ($i = $i_val; $i <= $quantity; $i++) {
            ?>
				<option value="<?php 
            echo esc_attr($i);
            ?>
"><?php 
            echo esc_attr($i);
            ?>
</option>
				<?php 
        }
        ?>
		</select>
		<?php 
    }
}
コード例 #2
0
 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;
                 }
             }
         }
     }
 }