cart_contents as $key => $value ) {
$cp = $value['event_tp'];
$value['data']->set_price($cp);
$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'];
if($mep_events_extra_prices){
echo "
";
foreach ( $mep_events_extra_prices as $field ) {
if($field['option_qty']>0){
?>
- x :
Ticket: ".$cart_item['event_ticket_type']." x ".$cart_item['event_ticket_qty'].": ".get_woocommerce_currency_symbol().$cart_item['event_ticket_price']."";
}
echo "
";
return $item_data;
}
}
add_filter( 'woocommerce_get_item_data', 'mep_display_custom_fields_text_cart', 10, 2 );
function mep_add_custom_fields_text_to_order_items( $item, $cart_item_key, $values, $order ) {
$mep_events_extra_prices = $values['event_extra_option'];
$event_user_info = $values['event_user_info'];
$event_ticket_type = $values['event_ticket_type'];
$event_ticket_price = $values['event_ticket_price'];
$event_ticket_qty = $values['event_ticket_qty'];
$product_id = $values['product_id'];
foreach ( $mep_events_extra_prices as $field ) {
if($field['option_qty']>0){
$item->add_meta_data( __( esc_attr( $field['option_name'] )." x ".$field['option_qty'], 'atn' ), get_woocommerce_currency_symbol().($field['option_qty'] *$field['option_price'] ) );
$opt_name = $product_id.str_replace(' ', '', $field['option_name']);
$opt_qty = $field['option_qty'];
// $tes = 0;
$tes = get_post_meta($product_id,"mep_xtra_$opt_name",true);
$ntes = ($tes+$opt_qty);
update_post_meta( $product_id, "mep_xtra_$opt_name",$ntes);
}
}
if($event_ticket_type){
$event_ticket_type = "Ticket:".$event_ticket_type;
$item->add_meta_data( __($event_ticket_type." x ".$event_ticket_qty),get_woocommerce_currency_symbol().$event_ticket_price);
$tck_name = $product_id.str_replace(' ', '', $event_ticket_type);
$tesqt = get_post_meta($product_id,"mep_xtra_$tck_name",true);
$ntesqt = ($tesqt+$event_ticket_qty);
update_post_meta( $product_id, "mep_xtra_$tck_name",$ntesqt);
}
$item->add_meta_data( __('_event_user_info'),$event_user_info);
}
add_action( 'woocommerce_checkout_create_order_line_item', 'mep_add_custom_fields_text_to_order_items', 10, 4 );