Can any one please suggest me how to change the product price when adding product to cart through admin.

I want to change the price of the product programmatically when adding product to cart.

1 Answer 1


Create events.xml in app/code/Vendor/Module/etc

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="sales_quote_add_item">
        <observer name="customprice" instance="Vendor\Module\Observer\CustomPrice" />

Create CustomPrice.php in Vendor\Module\Observer


    namespace Vendor\Module\Observer;

    use Magento\Framework\Event\ObserverInterface;
    use Magento\Framework\App\RequestInterface;
    use Magento\Framework\App\State;
    class CustomPrice implements ObserverInterface
    protected $_state;
    public function __construct(State $state){


        public function execute(\Magento\Framework\Event\Observer $observer) {
            $item = $observer->getEvent()->getData('quote_item');         
            $price = 100; //set your price here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.