コード例 #1
0
 function ticket_cart_button($atts)
 {
     global $tc;
     $tc_general_settings = get_option('tc_general_setting', false);
     extract(shortcode_atts(array('id' => false, 'title' => __('Add to Cart', 'tc'), 'show_price' => false, 'price_position' => 'after', 'price_wrapper' => 'span', 'price_wrapper_class' => 'price', 'soldout_message' => __('Tickets are sold out.', 'tc'), 'type' => 'cart', 'wrapper' => ''), $atts));
     $show_price = (bool) $show_price;
     if (isset($id)) {
         $ticket_type = new TC_Ticket($id, 'publish');
     }
     $event_id = get_post_meta($id, 'event_name', true);
     if (isset($ticket_type->details->ID) && get_post_status($event_id) == 'publish') {
         //check if ticket still exists
         if ($show_price) {
             $with_price_content = ' <span class="' . $price_wrapper_class . '">' . do_shortcode('[ticket_price id="' . $id . '"]') . '</span> ';
         } else {
             $with_price_content = '';
         }
         if (is_array($tc->get_cart_cookie()) && array_key_exists($id, $tc->get_cart_cookie())) {
             $button = sprintf('<' . $price_wrapper . ' class="tc_in_cart">%s <a href="%s">%s</a></' . $price_wrapper . '>', __('Ticket added to', 'tc'), $tc->get_cart_slug(true), __('Cart', 'tc'));
         } else {
             if ($ticket_type->is_ticket_exceeded_quantity_limit() === false) {
                 if (isset($tc_general_settings['force_login']) && $tc_general_settings['force_login'] == 'yes' && !is_user_logged_in()) {
                     $button = '<form class="cart_form">' . ($price_position == 'before' ? $with_price_content : '') . '<a href="' . wp_login_url(get_permalink()) . '" class="add_to_cart_force_login" id="ticket_' . $id . '"><span class="title">' . $title . '</span></a>' . ($price_position == 'after' ? $with_price_content : '') . '<input type="hidden" name="ticket_id" class="ticket_id" value="' . $id . '"/>' . '</form>';
                 } else {
                     $button = '<form class="cart_form">' . ($price_position == 'before' ? $with_price_content : '') . '<a href="#" class="add_to_cart" data-button-type="' . $type . '" id="ticket_' . $id . '"><span class="title">' . $title . '</span></a>' . ($price_position == 'after' ? $with_price_content : '') . '<input type="hidden" name="ticket_id" class="ticket_id" value="' . $id . '"/>' . '</form>';
                 }
             } else {
                 $button = '<span class="tc_tickets_sold">' . $soldout_message . '</span>';
             }
         }
         if ($id && get_post_type($id) == 'tc_tickets') {
             return $button;
         } else {
             return __('Unknown ticket ID', 'tc');
         }
     } else {
         return '';
     }
 }