Advertisement
BakerMan

EDD Tickets form (show # remaining tickets)

Feb 10th, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.15 KB | None | 0 0
  1. <form action="<?php echo esc_url( add_query_arg( 'eddtickets_process', 1, edd_get_checkout_uri() ) ); ?>"
  2.       class="cart" method="post"
  3.       enctype='multipart/form-data'>
  4.         <table width="100%" class="tribe-events-tickets">
  5.             <?php
  6.             global $edd_options;
  7.             $is_there_any_product         = false;
  8.             $is_there_any_product_to_sell = false;
  9.  
  10.             ob_start();
  11.             foreach ( $tickets as $ticket ) {
  12.  
  13.                 $product = edd_get_download( $ticket->ID );
  14.  
  15.                 $gmt_offset = ( get_option( 'gmt_offset' ) >= '0' ) ? ' +' . get_option( 'gmt_offset' ) : " " . get_option( 'gmt_offset' );
  16.                 $gmt_offset = str_replace( array( '.25', '.5', '.75' ), array( ':15', ':30', ':45' ), $gmt_offset );
  17.  
  18.                 $end_date = null;
  19.                 if ( ! empty( $ticket->end_date ) ){
  20.                     $end_date = strtotime( $ticket->end_date . $gmt_offset );
  21.                 }else{
  22.                     $end_date = strtotime( tribe_get_end_date( get_the_ID(), false, 'Y-m-d G:i' ) . $gmt_offset );
  23.                 }
  24.  
  25.                 $start_date = null;
  26.                 if ( !empty( $ticket->start_date ) )
  27.                     $start_date = strtotime( $ticket->start_date . $gmt_offset );
  28.  
  29.  
  30.                 if ( ! TribeEDDTickets::is_stock_left( $product->ID ) || ( empty( $start_date ) || time() > $start_date ) && (  empty( $end_date ) || time() < $end_date ) ) {
  31.  
  32.                     $is_there_any_product = true;
  33.  
  34.                     echo sprintf( "<input type='hidden' name='product_id[]' value='%d'>", $ticket->ID );
  35.  
  36.                     echo "<tr>";
  37.                     echo "<td width='75' class='edd'>";
  38.  
  39.  
  40.                     if ( TribeEDDTickets::is_stock_left( $product->ID ) ) {
  41.  
  42.                         echo '<input type="number" class="edd-input" min="0" name="quantity_' . $ticket->ID . '" value="0"/>';
  43.  
  44.                         // How many remain?
  45.                         $limit = (int) get_post_meta( $product->ID, '_stock', true );
  46.                         $sold = (int) edd_get_download_sales_stats( $product->ID );
  47.                         $remaining = absint( $limit - $sold );
  48.  
  49.                         if ( $remaining > 0 ) echo
  50.                             " <span class='edd_tickets_remaining'> $remaining tickets still available! </span> ";
  51.  
  52.                         $is_there_any_product_to_sell = true;
  53.  
  54.                     } else {
  55.                         echo "<span class='tickets_nostock'>" . esc_html__( 'Out of stock!', 'tribe-eddtickets' ) . "</span>";
  56.                     }
  57.                     echo "</td>";
  58.  
  59.                     echo "<td nowrap='nowrap' class='tickets_name'>";
  60.                     echo $ticket->name;
  61.                     echo "</td>";
  62.  
  63.                     echo "<td class='tickets_price'>";
  64.                     echo edd_price( $product->ID );
  65.                     echo "</td>";
  66.  
  67.                     echo "<td class='tickets_description'>";
  68.                     echo $ticket->description;
  69.                     echo "</td>";
  70.  
  71.                     echo "</tr>";
  72.                 }
  73.  
  74.             }
  75.             $contents = ob_get_clean();
  76.             if ( $is_there_any_product ) {
  77.                 ?>
  78.                 <h2 class="tribe-events-tickets-title"><?php _e( 'Tickets', 'tribe-eddtickets' );?></h2>
  79.                 <?php echo $contents; ?>
  80.                 <?php if ( $is_there_any_product_to_sell ) : ?>
  81.                     <?php
  82.                     $color = isset( $edd_options[ 'checkout_color' ] ) ? $edd_options[ 'checkout_color' ] : 'gray';
  83.                     $color = ( $color == 'inherit' ) ? '' : $color;
  84.                     ?>
  85.                     <tr>
  86.                         <td colspan="4" class='eddtickets-add'>
  87.  
  88.                             <button type="submit" class="edd-submit button <?php echo $color; ?>"><?php esc_html_e( 'Add to cart', 'tribe-eddtickets' );?></button>
  89.                         </td>
  90.                     </tr>
  91.                     <?php
  92.                 endif;
  93.             }
  94.             ?>
  95.  
  96.         </table>
  97.  
  98. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement