Advertisement
BakerMan

Hide/show GCal links according to stock (WooTickets) (2)

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