Adding custom cart price with Ajax in wordpress
Try to change your add_custom_price_callback() as follows. Untested but should work. function add_custom_price_callback() { $custom_price = intval($_POST[‘p_m’]); $target_product_id = intval($_POST[‘s_o_v’]); foreach ( WC()->cart->get_cart() as $key=>$value ) { //Single product if ( $value[‘product_id’] == $target_product_id ) { $value[‘data’]->set_price($custom_price); } //For variation if ( $value[‘variation_id’] == $target_product_id ) { $value[‘data’]->set_price($custom_price); } } //to check if is work … Read more