Steps to Add Product To Cart With Custom Price in Magento 2
Step 1: First, create a file “events.xml” at the below-given path.
appcodeVendorExtensionetcfrontendevents.xml

Now add the below code
Step 2: Now, we need one more file named “Customprice.php” that overrides our price. Go to the below path
appcodeVendorExtensionObserverCustomprice.php
And finally, add the code as mentioned below,
<?php namespace VendorExtensionObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestInterface;
class Customprice implements ObserverInterface {
public function execute(MagentoFrameworkEventObserver $observer) {
$item =$observer->getEvent()->getData(‘quote_item’);
$item =($item->getParentItem() ? $item->getParentItem() : $item );
$price =100; //set your price here
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
$item->getProduct()->setIsSuperMode(true);
}
}