1function before_calculate_totals( $cart_obj ) {
2 if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
3 return;
4 }
5 // Iterate through each cart item
6 foreach( $cart_obj->get_cart() as $key=>$value ) {
7 if( isset( $value['csCost'] ) ) {
8 $getPrice = $value['data']->get_price();
9 $price = $value['csCost'] + $getPrice;
10 $value['data']->set_price( ( $price ) );
11 }
12 if( isset( $value['setCost'] ) ) {
13 $getPrice = $value['data']->get_price();
14 $price = $value['setCost'] + $getPrice;
15 $value['data']->set_price( ( $price ) );
16 }
17
18 }
19}
20add_action( 'woocommerce_before_calculate_totals', 'before_calculate_totals', 10, 1 );