BakerMan

WooTickets (Show Inventory) Modification of Daniels Code

Mar 6th, 2013
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.78 KB | None | 0 0
  1. <?php global $woocommerce; ?>
  2.  
  3. <form action="<?php echo esc_url( add_query_arg( 'wootickets_process', 1, $woocommerce->cart->get_cart_url() ) ); ?>"
  4.       class="cart" method="post"
  5.       enctype='multipart/form-data'>
  6.     <table width="100%" class="tribe-events-tickets">
  7.         <?php
  8.  
  9.         $is_there_any_product         = false;
  10.         $is_there_any_product_to_sell = false;
  11.  
  12.         $gmt_offset = ( get_option( 'gmt_offset' ) >= '0' ) ? ' +' . get_option( 'gmt_offset' ) : " " . get_option( 'gmt_offset' );
  13.         $gmt_offset = str_replace( array( '.25', '.5', '.75' ), array( ':15', ':30', ':45' ), $gmt_offset );
  14.  
  15.         ob_start();
  16.         foreach ( $tickets as $ticket ) {
  17.  
  18.             global $product;
  19.  
  20.             if ( class_exists( 'WC_Product_Simple' ) ) {
  21.                 $product = new WC_Product_Simple( $ticket->ID );
  22.             } else {
  23.                 $product = new WC_Product( $ticket->ID );
  24.             }
  25.  
  26.             $end_date = $ticket->end_date;
  27.             if ( empty( $ticket->end_date ) ) {
  28.  
  29.                 $event_end_date = tribe_get_end_date();
  30.  
  31.                 if ( tribe_get_all_day( get_the_ID() ) )
  32.                     $event_end_date = date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( TribeDateUtils::endOfDay( $event_end_date ) ) );
  33.  
  34.                 $end_date = apply_filters( 'wootickets_default_end_date', $event_end_date, $ticket->ID );
  35.  
  36.                 if ( method_exists( 'DateTime', 'createFromFormat' ) ) {
  37.                     $end_date = DateTime::createFromFormat( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $end_date );
  38.                 } else {
  39.                     $end_date = new DateTime( date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $end_date ) ) );
  40.                 }
  41.  
  42.                 if ( !empty( $end_date ) )
  43.                     $end_date = $end_date->format( 'Y-m-d g:i a' );
  44.             }
  45.             $end_date = strtotime( $end_date . $gmt_offset );
  46.  
  47.             $start_date = null;
  48.             if ( !empty( $ticket->start_date ) )
  49.                 $start_date = strtotime( $ticket->start_date . $gmt_offset );
  50. //              if ( !empty( $ticket->start_date ) ) {
  51. //                  $start_date = DateTime::createFromFormat( get_option( 'date_format' ), $ticket->start_date );
  52. //                  $start_date = strtotime( $start_date->format( 'Y-m-d' ) . $gmt_offset );
  53. //              }
  54.  
  55.  
  56.             if ( ( !$product->is_in_stock() ) || ( empty( $start_date ) || time() > $start_date ) && ( time() < $end_date ) ) {
  57.  
  58.                 $is_there_any_product = true;
  59.  
  60.                 echo sprintf( "<input type='hidden' name='product_id[]' value='%d'>", $ticket->ID );
  61.  
  62.                 echo "<tr>";
  63.                 echo "<td width='75' class='woocommerce'>";
  64.  
  65.  
  66.                 if ( $product->is_in_stock() ) {
  67.  
  68.                     woocommerce_quantity_input( array( 'input_name'  => 'quantity_' . $ticket->ID,
  69.                         'input_value' => 0,
  70.                         'min_value'   => 0,
  71.                         'max_value'   => $product->backorders_allowed() ? '' : $product->get_stock_quantity(), ) );
  72.  
  73.                     $is_there_any_product_to_sell = true;
  74.  
  75.                 } else {
  76.                     echo "<span class='tickets_nostock'>" . esc_html__( 'Out of stock!', 'tribe-wootickets' ) . "</span>";
  77.                 }
  78.                 echo "</td>";
  79.  
  80.                 echo "<td nowrap='nowrap' class='tickets_name'>";
  81.                 echo $ticket->name;
  82.                 echo "</td>";
  83.  
  84.                 echo "<td class='tickets_price'>";
  85.                 echo $product->get_price_html();
  86.                 echo "</td>";
  87.  
  88.                 echo "<td class='tickets_description'>";
  89.                 echo $ticket->description;
  90.                 echo "</td>";
  91.  
  92.                 echo "<td class='tickets_description'> Available:";
  93.                 echo $ticket->stock;
  94.                 echo "</td>";
  95.  
  96.  
  97.                 echo "</tr>";
  98.             }
  99.  
  100.         }
  101.         $contents = ob_get_clean();
  102.         if ( $is_there_any_product ) {
  103.             ?>
  104.             <h2 class="tribe-events-tickets-title"><?php _e( 'Tickets', 'tribe-wootickets' );?></h2>
  105.             <?php echo $contents; ?>
  106.             <?php if ( $is_there_any_product_to_sell ) { ?>
  107.                 <tr>
  108.                     <td colspan="4" class='woocommerce'>
  109.  
  110.                         <button type="submit"
  111.                                 class="button alt"><?php esc_html_e( 'Add to cart', 'tribe-wootickets' );?></button>
  112.                     </td>
  113.                 </tr>
  114.             <?php
  115.             }
  116.         }
  117.         ?>
  118.  
  119.     </table>
  120.  
  121. </form>
Advertisement
Add Comment
Please, Sign In to add comment