Assuming this is Magento 1.x if not let me know and I'll provide M2 version
You need to do this by hooking into the add to cart action using the observer and do something similar to this
private function replaxePrice($product_id,$newPrice){
$quote = Mage::getSingleton('checkout/session')->getQuote();
foreach ($quote->getAllVisibleItems() as $item) {
if($item->getProduct()->getId() != $product_id) continue;
if ($newPrice > 0) {
$item->setCustomPrice($newPrice);
$item->setOriginalCustomPrice($newPrice);
$item->getProduct()->setIsSuperMode(true);
}
}
$quote->save();
}
Sorry about poor formatting. Only certain thing I can do on mobile
Why reinvent the wheel, I has someone ask me this recently and I sent them this reference
Updated for M2
https://webkul.com/blog/magento2-set-custom-price-of-product/
Hope this resolved your issues