Add Ad-dons Data

add_filter( ‘woocommerce_add_cart_item_data’,’add_cart_item_data1′,10,2);
function add_cart_item_data1($cart_item_meta,$product_id) {
session_start();
global $woocommerce;
$cart_step_deta = array();
foreach($_SESSION[‘step_data’] as $step){
foreach($step as $step_itm):
$catname = get_customization_cat_name($step_itm[‘stepcat’],$product_id);
$cusprice = get_customization_price($step_itm[‘stepcat’],$step_itm[‘catpost’],$product_id);
$cart_step_deta[]=array(‘name’=>$catname,’price’=>$cusprice,’value’=> get_the_title($step_itm[‘catpost’]));
endforeach;
}
foreach($_SESSION[‘measurement’] as $mkey => $mvalues){
$measurement_deta[]=array(‘name’=>str_replace(‘_’,’ ‘,$mkey),’price’=>0,’value’=>$mvalues);
}
$cart_item_meta=array(‘cart_step_deta’=>$cart_step_deta,’measurement_deta’=>$measurement_deta);

unset($_SESSION[‘step_data’]);
unset($_SESSION[‘measurement’]);
unset($_SESSION[‘custom_step’]);
unset($_SESSION[‘custom_product’]);
unset($_SESSION[‘step_taxoid’]);
unset($_SESSION[‘step_taxo’]);

return $cart_item_meta;
}

add_filter(‘woocommerce_get_cart_item_from_session’,’get_cart_item_from_session1′,10,2);
function get_cart_item_from_session1($cart_item,$values) {
if ( ! empty( $values[‘cart_step_deta’] ) ) {
$cart_item[‘cart_step_deta’] = $values[‘cart_step_deta’];
$cart_item[‘measurement_deta’] = $values[‘measurement_deta’];
$cart_item = add_cart_item1( $cart_item );
}
return $cart_item;
}
add_filter( ‘woocommerce_add_cart_item’,’add_cart_item1′,10,1);
function add_cart_item1( $cart_item ) {
if (isset($cart_item[‘cart_step_deta’])) :
$extra_cost = 0;
foreach ($cart_item[‘cart_step_deta’] as $addon) :
if ($addon[‘price’]>0) $extra_cost += $addon[‘price’];
endforeach;
$cart_item[‘data’]->adjust_price( $extra_cost );
endif;
return $cart_item;
}

add_filter( ‘woocommerce_get_item_data’,’get_item_data1′, 10, 2 );
function get_item_data1( $other_data, $cart_item ) {
if (isset($cart_item[‘cart_step_deta’])) :
foreach ($cart_item[‘cart_step_deta’] as $addon) :
$name = $addon[‘name’];
if ($addon[‘price’]>0) $name .= ‘ (‘ . woocommerce_price($addon[‘price’]) . ‘)’;
$other_data[] = array(
‘name’ => $name,
‘value’ => $addon[‘value’],
‘display’ => isset($addon[‘display’]) ? $addon[‘display’] : ”
);
endforeach;
endif;
return $other_data;
}