Home › Forums › Ticket Products › Event Tickets Plus › Wooticket + Woocomerce product addon
- This topic has 1 reply, 2 voices, and was last updated 10 years, 8 months ago by
Geoff.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
August 18, 2015 at 7:55 am #996983
Christelle
ParticipantIn case you need to use Woocommerce product addon with Wooticket, you can modify the file tickets.php this way ;
<?php global $woocommerce; $is_there_any_product = false; $is_there_any_product_to_sell = false; ob_start(); ?> <?php ?> <form action="<?php echo esc_url( $woocommerce->cart->get_cart_url() ) ?>" class="cart" method="post" enctype='multipart/form-data'> <h2 class="tribe-events-tickets-title"><?php _e( 'Tickets', 'tribe-wootickets' ) ?></h2> <table width="100%" class="tribe-events-tickets"> <?php foreach ( $tickets as $ticket ) { global $product; global $wpdb; //Modification : get product addon attributes $results = $wpdb->get_row('SELECT meta_value FROM wp_postmeta WHERE post_id = '.$ticket->ID.' AND meta_key = "_product_addons"'); $results = unserialize($results->meta_value); if ( class_exists( 'WC_Product_Simple' ) ) { $product = new WC_Product_Simple( $ticket->ID ); } else { $product = new WC_Product( $ticket->ID ); } $gmt_offset = ( get_option( 'gmt_offset' ) >= '0' ) ? ' +' . get_option( 'gmt_offset' ) : " " . get_option( 'gmt_offset' ); $gmt_offset = str_replace( array( '.25', '.5', '.75' ), array( ':15', ':30', ':45' ), $gmt_offset ); $end_date = null; if ( ! empty( $ticket->end_date ) ){ $end_date = strtotime( $ticket->end_date . $gmt_offset ); } else { $end_date = strtotime( tribe_get_end_date( get_the_ID(), false, 'Y-m-d G:i' ) . $gmt_offset ); } $start_date = null; if ( ! empty( $ticket->start_date ) ){ $start_date = strtotime( $ticket->start_date . $gmt_offset ); } if ( ! empty( $ticket->start_date ) ) { } if ( ( empty( $start_date ) || time() > $start_date ) && ( empty( $end_date ) || time() < $end_date ) ) { $is_there_any_product = true; echo sprintf( "<input type='hidden' name='product_id[]' value='%d'>", $ticket->ID ); echo "<tr>"; echo "<td class='woocommerce'>"; if ( $product->is_in_stock() ) { //Modificatin : loop over types of attributes if($results !== false){ foreach ( $results as $j => $fieldoption ) { echo wptexturize($fieldoption["description"]); if($fieldoption['type'] == "checkbox"){ $price = $fieldoption['price'] > 0 ? '(' . woocommerce_price( get_product_addon_price_for_display( $fieldoption['price'] ) ) . ')' : ''; $selected = isset( $_POST[ 'addon-' . sanitize_title( $addon['field-name'] ) ] ) ? $_POST[ 'addon-' . sanitize_title( $addon['field-name'] ) ] : array(); if ( ! is_array( $selected ) ) { $selected = array( $selected ); } $current_value = ( in_array( sanitize_title( $option['label'] ), $selected ) ) ? 1 : 0; //var_dump($fieldoption["description"]); foreach ( $fieldoption['options'] as $i => $option ) { // var_dump($option); //$price = $option['price'] > 0 ? '(' . woocommerce_price( get_product_addon_price_for_display( $option['price'] ) ) . ')' : ''; ?> <p class="form-row form-row-wide addon-wrap-<?php echo sanitize_title( $addon['field-name'] ) . '-' . $i; ?>"> <label><input type="checkbox" class="addon addon-checkbox" data-price="<?php echo get_product_addon_price_for_display( $fieldoption['price'] ); ?>" name="addon-<?php echo $ticket->ID; ?>-<?php echo sanitize_title( $fieldoption["name"] ); ?>[]" value="<?php echo sanitize_title( $option['label'] ); ?>"> <?php echo $option["label"] ; ?> </label> </p> <?php } } if($fieldoption['type'] == "radiobutton"){ foreach ( $fieldoption['options'] as $i => $option ) { ?> <p class="form-row form-row-wide addon-wrap-<?php echo sanitize_title( $addon['field-name'] ) . '-' . $i; ?>"> <label><input type="radio" class="addon addon-radio" name="addon-<?php echo $ticket->ID; ?>-<?php echo sanitize_title( $fieldoption["name"] ); ?>[]" data-price="<?php echo get_product_addon_price_for_display( $option['price'] ); ?>" value="<?php echo sanitize_title( $option['label'] ); ?>" <?php checked( $current_value, 1 ); ?> /> <?php echo wptexturize( $option['label'] . ' ' . $price ); ?></label> </p> <?php } } if($fieldoption['type'] == "custom"){ //var_dump($fieldoption["options"][0]["label"]); $addon_fieldname = "addon-".$ticket->ID."-".sanitize_title( $fieldoption['name']); $addon_key = 'addon-' . sanitize_title( $fieldoption['name'] ); $option_key = empty( $fieldoption['name'] ) ? $key : sanitize_title( $fieldoption["options"][0]["label"] ); $current_value = isset( $_POST[ $addon_key ] ) && isset( $_POST[ $addon_key ][ $option_key ] ) ? $_POST[ $addon_key ][ $option_key ] : ''; $price = $fieldoption['price'] > 0 ? '(' . woocommerce_price( get_product_addon_price_for_display( $fieldoption['price'] ) ) . ')' : ''; ?> <p class="form-row form-row-wide addon-wrap-<?php echo sanitize_title( $addon_fieldname ); ?>"> <?php if ( ! empty( $fieldoption['name'] ) ) : ?> <label><?php //echo wptexturize( $fieldoption['name'] ) . ' ' . $price; ?></label><br> <?php endif; ?> <input type="text" class="input-text addon addon-custom" data-price="<?php echo get_product_addon_price_for_display( $fieldoption['price'] ); ?>" name="<?php echo $addon_fieldname ?>[<?php echo $option_key; ?>]" value="" <?php if ( ! empty( $fieldoption['max'] ) ) echo 'maxlength="' . $fieldoption['max'] .'"'; ?> /> </p> <?php } if($fieldoption['type'] == "select"){ $addon_fieldname = "addon-".$ticket->ID."-".sanitize_title( $fieldoption['name']); ?> <p class="form-row form-row-wide addon-wrap-<?php echo sanitize_title( $addon_fieldname ); ?>"> <select class="addon addon-select" name="<?php echo sanitize_title( $addon_fieldname ); ?>"> <?php if ( ! isset( $addon['required'] ) ) : ?> <option value=""><?php _e('None', 'woocommerce-product-addons'); ?></option> <?php else : ?> <option value=""><?php _e('Select an option...', 'woocommerce-product-addons'); ?></option> <?php endif; ?> <?php foreach ( $fieldoption['options'] as $option ) : $loop ++; $price = $option['price'] > 0 ? ' (' . woocommerce_price( get_product_addon_price_for_display( $option['price'] ) ) . ')' : ''; ?> <option data-price="<?php echo get_product_addon_price_for_display( $option['price'] ); ?>" value="<?php echo sanitize_title( $option['label'] ) . '-' . $loop; ?>" <?php selected( $current_value, sanitize_title( $option['label'] ) . '-' . $loop ); ?>><?php echo wptexturize( $option['label'] ) . $price ?></option> <?php endforeach; ?> </select> </p> <?php } } } // Max quantity will be left open if backorders allowed, restricted to 1 if the product is // constrained to be sold individually or else set to the available stock quantity $max_quantity = $product->backorders_allowed() ? '' : $product->get_stock_quantity(); $max_quantity = $product->is_sold_individually() ? 1 : $max_quantity; echo _e( 'Quantity', 'tribe-wootickets' )." :"; woocommerce_quantity_input( array( 'input_name' => 'quantity_' . $ticket->ID, 'input_value' => 0, 'min_value' => 0, 'max_value' => $max_quantity ) ); $is_there_any_product_to_sell = true; } else { echo "<span class='tickets_nostock'>" . esc_html__( 'Out of stock!', 'tribe-wootickets' ) . "</span>"; } echo "</td>"; echo "<td nowrap='nowrap' class='tickets_name'>"; echo $ticket->name; echo "</td>"; echo "<td class='tickets_price'>"; echo $this->get_price_html( $product ); echo "</td>"; echo "<td class='tickets_description'>"; echo $ticket->description; echo "</td>"; echo "</tr>"; } } if ( $is_there_any_product_to_sell ) : ?> <tr> <td colspan="4" class='woocommerce add-to-cart'> <button type="submit" name="wootickets_process" value="1" class="button alt"><?php esc_html_e( 'Add to cart', 'tribe-wootickets' );?></button> </td> </tr> <?php endif ?> </table> </form> <?php $content = ob_get_clean(); if ( $is_there_any_product ) { echo $content; }August 18, 2015 at 3:17 pm #997096Geoff
MemberRight on and thanks a TON, @Christelle! That’s a handy thing to know and I’m sure others in the community will find that helpful as well. I’ve shared this with the team so it’s on everyone’s radar.
Cheers and thanks again for your help!
Geoff
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- The topic ‘Wooticket + Woocomerce product addon’ is closed to new replies.
