0){
if ( $extra_service_name[$i] != '' ) :
$event_extra[$i]['service_name'] = stripslashes( strip_tags( $extra_service_name[$i] ) );
endif;
if ( $extra_service_price[$i] != '' ) :
$event_extra[$i]['service_price'] = stripslashes( strip_tags( $extra_service_price[$i] ) );
endif;
if ( $extra_service_qty[$i] != '' ) :
$event_extra[$i]['service_qty'] = stripslashes( strip_tags( $extra_service_qty[$i] ) );
endif;
}
$extprice = ($extra_service_price[$i]*$extra_service_qty[$i]);
$tp = ($tp+$extprice);
}
}
if(isset($_POST['mep_event_ticket_type'])){
$ttp = $_POST['mep_event_ticket_type'];
$ttpqt = $_POST['tcp_qty'];
$ticket_type = mep_get_order_info($ttp,1);
$ticket_type_price = (mep_get_order_info($ttp,0)*$ttpqt);
$cart_item_data['event_ticket_type'] = $ticket_type;
$cart_item_data['event_ticket_price'] = $ticket_type_price;
$cart_item_data['event_ticket_qty'] = $ttpqt;
$tp = $tp+$ticket_type_price;
}
$form_position = mep_get_option( 'mep_user_form_position', 'general_attendee_sec', 'details_page' );
if($form_position=='details_page'){
$user = mep_save_attendee_info_into_cart($product_id);
}else{
$user = '';
}
$mep_event_ticket_type = get_post_meta($product_id, 'mep_event_ticket_type', true) ? get_post_meta($product_id, 'mep_event_ticket_type', true) : array();
$cnt = 0;
$vald = 0;
$ticket_type_arr = array();
if(is_array($mep_event_ticket_type) && sizeof($mep_event_ticket_type) > 0){
foreach($mep_event_ticket_type as $_type){
$cart_arr = $new[$cnt];
$name_key = array_search($_type['option_name_t'],$cart_arr);
$qty_key = array_search($_type['option_qty_t'],$cart_arr);
if(is_array($name_key)){
$total_found = count($name_key);
}else{
$total_found = 0;
}
if($cart_arr['option_qty'] > 0){
$ticket_type_arr[$cnt]['ticket_name'] = stripslashes( strip_tags( $cart_arr[$name_key] ) );
$ticket_type_arr[$cnt]['ticket_qty'] = stripslashes( strip_tags( $cart_arr['option_qty'] ) );
$ticket_type_arr[$cnt]['ticket_price'] = stripslashes( strip_tags( $cart_arr['option_price'] ) );
$ticket_type_arr[$cnt]['event_date'] = stripslashes( strip_tags( $mep_event_start_date ) );
$validate[$cnt]['ticket_qty'] = $vald + stripslashes( strip_tags( $cart_arr['option_qty'] ) );
$validate[$cnt]['event_id'] = stripslashes( strip_tags( $product_id ) );
}
$cnt++;
}
}
if($recurring == 'yes'){
$recurring_event_date = isset($_POST['recurring_event_date']) ? $_POST['recurring_event_date'] : array();
}else{
$recurring_event_date = array();
}
$cart_item_data['event_ticket_info'] = $ticket_type_arr;
$cart_item_data['event_validate_info'] = $validate;
$cart_item_data['event_extra_option'] = $new;
$cart_item_data['event_user_info'] = $user;
$cart_item_data['event_tp'] = $tp;
$cart_item_data['line_total'] = $tp;
$cart_item_data['line_subtotal'] = $tp;
$cart_item_data['event_extra_service'] = $event_extra;
$cart_item_data['event_cart_location'] = $event_cart_location;
$cart_item_data['event_cart_date'] = $mep_event_start_date;
$cart_item_data['event_recurring_date'] = array_unique($recurring_event_date);
$cart_item_data['event_recurring_date_arr'] = $recurring_event_date;
// $cart_item_data['event_cart_date'] = $event_cart_date;
}
$cart_item_data['event_id'] = $product_id;
return $cart_item_data;
}
add_filter( 'woocommerce_add_cart_item_data', 'mep_add_custom_fields_text_to_cart_item', 90, 3);
add_action( 'woocommerce_before_calculate_totals', 'mep_add_custom_price',90,1 );
function mep_add_custom_price( $cart_object ) {
foreach ( $cart_object->cart_contents as $key => $value ) {
$eid = $value['event_id'];
if (get_post_type($eid) == 'mep_events') {
$cp = $value['event_tp'];
$value['data']->set_price($cp);
$value['data']->set_regular_price($cp);
$value['data']->set_sale_price($cp);
$value['data']->set_sold_individually('yes');
$new_price = $value['data']->get_price();
}
}
}
function mep_display_custom_fields_text_cart( $item_data, $cart_item ) {
$mep_events_extra_prices = $cart_item['event_extra_option'];
$eid = $cart_item['event_id'];
if (get_post_type($eid) == 'mep_events') {
$user_info = $cart_item['event_user_info'];
$ticket_type_arr = $cart_item['event_ticket_info'];
$event_extra_service = $cart_item['event_extra_service'];
$event_recurring_date = $cart_item['event_recurring_date'];
// echo '
';
// print_r($user_info);
$recurring = get_post_meta($eid, 'mep_enable_recurring', true) ? get_post_meta($eid, 'mep_enable_recurring', true) : 'no';
echo "
";
if($recurring == 'yes'){
if(is_array($event_recurring_date) && sizeof($event_recurring_date) > 0){
foreach($event_recurring_date as $_event_recurring_date){
?>
- :
0){
echo '- ';
foreach($user_info as $userinf){
?>
';
}else{
?>
- :
- :
0){
foreach($ticket_type_arr as $ticket){
echo '- '.$ticket['ticket_name']." - ".wc_price($ticket['ticket_price']).' x '.$ticket['ticket_qty'].' = '.wc_price($ticket['ticket_price'] * $ticket['ticket_qty']).'
';
}
}
if(is_array($event_extra_service) && sizeof($event_extra_service) > 0){
foreach($event_extra_service as $extra_service){
echo '- '.$extra_service['service_name']." - ".wc_price($extra_service['service_price']).' x '.$extra_service['service_qty'].' = '.wc_price($extra_service['service_price'] * $extra_service['service_qty']).'
';
}
}
echo "
";
}
return $item_data;
}
add_filter( 'woocommerce_get_item_data', 'mep_display_custom_fields_text_cart', 90, 2 );
add_action( 'woocommerce_after_checkout_validation', 'mep_checkout_validation');
function mep_checkout_validation( $posted ) {
global $woocommerce;
$items = $woocommerce->cart->get_cart();
foreach($items as $item => $values) {
$event_id = $values['event_id'];
$total_seat = mep_event_total_seat($event_id,'total');
$total_resv = mep_event_total_seat($event_id,'resv');
$total_sold = mep_ticket_sold($event_id);
$total_left = $total_seat - ($total_sold + $total_resv);
;
$event_validate_info = $values['event_validate_info'];
$ee = 0;
foreach($event_validate_info as $inf){
$ee = $ee + $inf['ticket_qty'];
}
if($ee > $total_left) {
$event = get_the_title($event_id);
wc_add_notice( __( "Sorry, Seats are not available in $event, Available Seats $total_left but you selected $ee", 'mage-eventpress' ), 'error' );
}
}
}
function mep_add_custom_fields_text_to_order_items( $item, $cart_item_key, $values, $order ) {
$eid = $values['event_id'];
if (get_post_type($eid) == 'mep_events') {
$mep_events_extra_prices = $values['event_extra_option'];
if(isset($values['event_ticket_type'])){
$event_ticket_type = $values['event_ticket_type'];
}else{
$event_ticket_type = " ";
}
if(isset($values['event_ticket_price'])){
$event_ticket_price = $values['event_ticket_price'];
}else{
$event_ticket_price = " ";
}
if(isset($values['event_ticket_qty'])){
$event_ticket_qty = $values['event_ticket_qty'];
}else{
$event_ticket_qty = " ";
}
$product_id = $values['product_id'];
$cart_location = $values['event_cart_location'];
$event_extra_service = $values['event_extra_service'];
$ticket_type_arr = $values['event_ticket_info'];
$cart_date = $values['event_cart_date'];
$form_position = mep_get_option( 'mep_user_form_position', 'general_attendee_sec', 'details_page' );
if($form_position=='details_page'){
$event_user_info = $values['event_user_info'];
}else{
$event_user_info = mep_save_attendee_info_into_cart($eid);
}
$recurring = get_post_meta($eid, 'mep_enable_recurring', true) ? get_post_meta($eid, 'mep_enable_recurring', true) : 'no';
if($recurring == 'yes'){
$event_recurring_date = $values['event_recurring_date'];
$event_recurring_date_arr = $values['event_recurring_date_arr'];
if(is_array($event_recurring_date) && sizeof($event_recurring_date) > 0){
foreach($event_recurring_date as $_event_recurring_date){
$item->add_meta_data('Date',get_mep_datetime($_event_recurring_date, 'date-time-text'));
}
}
}else{
$event_recurring_date_arr = array();
$item->add_meta_data('Date',get_mep_datetime($cart_date, 'date-time-text'));
}
$item->add_meta_data('_recurring_date_arr',$event_recurring_date_arr);
$item->add_meta_data('Location',$cart_location);
$item->add_meta_data('_event_ticket_info',$values['event_ticket_info']);
if(is_array($ticket_type_arr) && sizeof($ticket_type_arr) > 0){
foreach($ticket_type_arr as $ticket){
$ticket_type_name = $ticket['ticket_name']." - ".wc_price($ticket['ticket_price']).' x '.$ticket['ticket_qty'].' = ';
$ticket_type_val= wc_price($ticket['ticket_price'] * $ticket['ticket_qty']);
$item->add_meta_data($ticket_type_name, $ticket_type_val );
}
}
if(is_array($event_extra_service) && sizeof($event_extra_service) > 0){
foreach($event_extra_service as $extra_service){
$service_type_name = $extra_service['service_name']." - ".wc_price($extra_service['service_price']).' x '.$extra_service['service_qty'].' = ';
$service_type_val= wc_price($extra_service['service_price'] * $extra_service['service_qty']);
$item->add_meta_data($service_type_name, $service_type_val );
}
}
if($event_ticket_type){
}else{
$item->add_meta_data('_event_ticket_type','normal');
}
$item->add_meta_data('_event_user_info',$event_user_info);
$item->add_meta_data('_no_of_ticket',count($event_user_info));
$item->add_meta_data('_event_service_info',$mep_events_extra_prices);
$item->add_meta_data('event_id',$eid);
$item->add_meta_data('_product_id',$eid);
$item->add_meta_data('_event_extra_service',$event_extra_service);
}
}
add_action( 'woocommerce_checkout_create_order_line_item', 'mep_add_custom_fields_text_to_order_items', 90, 4 );