I have custom products and i have added the products in the cart but it should be quantity based calculation for those products. how to change the product subtotal price in woocomerce. the product subtotal should override with my price. how to override it. Please check with my below code
$values = array();
$post_values = array();
$i=0;
foreach($_POST['post_quantity'] as $key =>$value){
$values[] = "('{$_POST['product_id'][$key]}', '{$_POST['post_quantity'][$key]}',
'{$_POST['product_price'][$key]}',
'{$_POST['product_duplicate_price'][$key]}',
'{$_POST['product_description'][$key]}',
'{$_POST['product_material'][$key]}')";
$wpdb->insert('wp_posts', array(
'post_title' => 'xxxx '.$_POST['quoted_sid'].'Quote ID: '.$_POST['quoted_sid'][$key].' - Product ID: '.$_POST['product_id'][$key],
'post_content' => $_POST['product_description'][$key],
'post_date' => date('Y-m-d H:i:s'),
'post_status' => 'publish',
'post_author' => 1,
'post_type' =>'product'
));
$lastid[$i] = $wpdb->insert_id;
$date[$i] = date('Y-m-d H:i:s');
//calculation for quantity
$regular_price =
$_POST['product_price'][$key] + $_POST['product_duplicate_price'][$key]*($_POST['post_quantity'][$key]-1);
//$regular_price /$_POST['post_quantity'][$key];
//echo number_format((float)$regular_price,2,'.','').'</br>';
add_post_meta($lastid[$i], '_regular_price', number_format((float)$regular_price,2,'.',''));
add_post_meta($lastid[$i], '_price', number_format((float)$_POST['product_price'][$key],2,'.',''));
add_post_meta($lastid[$i],'_visibility','visible');
add_post_meta($lastid[$i], '_stock_status', 'instock' );
add_post_meta($lastid[$i], '_weight', '11' );
add_post_meta($lastid[$i], '_sku', 'Quoted Stencil_'.$_POST['product_id'][$key] );
add_post_meta($lastid[$i], '_duplicate_price', $_POST['product_duplicate_price'][$key] );
add_post_meta($lastid[$i], '_material', $_POST['product_material'][$key] );
$post_values['product_id'][] = $lastid[$i];
$post_values['product_quantity'][] = $_POST['post_quantity'][$key];
$i++;
}
//print_r($post_values);
$j=0;
foreach ( $post_values as $product_id ) {
$woocommerce->cart->add_to_cart( $post_values['product_id'][$j] ,$post_values['product_quantity'][$j],$cart_item_data);
$j++;
}
//exit;
exit( wp_redirect( home_url( "cart" ) ) );