---
title: "How to Add Product To Cart With Custom Price in Magento 2?"
url: "https://magecomp.com/blog/add-product-to-cart-with-custom-price-magento-2/"
date: "2019-04-05T16:40:04+00:00"
modified: "2025-01-30T10:02:20+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "Magento Tutorials"
word_count: 493
reading_time: "3 min read"
summary: "Hello, Magento Friends!"
description: "Learn more about how to Programmatically Add Product to Cart with Custom prices in Magento 2 to boost the user experience of your Magento 2 store."
keywords: "Magento Tutorials"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Secure Your Magento Website From Brute Force Attack"
    url: "https://magecomp.com/blog/secure-magento-website-brute-force-attack/"
  - title: "Best 7 ways to use Social Media Effectively to Boost Your Magento Sales"
    url: "https://magecomp.com/blog/best-ways-to-use-social-media-to-boost-magento-sales/"
  - title: "How to Create UI Component Grid and Form in Magento 2"
    url: "https://magecomp.com/blog/create-ui-component-grid-and-form-magento-2/"
---

# How to Add Product To Cart With Custom Price in Magento 2?

_Published: April 5, 2019_  
_Author: Dhiren Vasoya_  

![How to Add Product To Cart With Custom Price in Magento 2](https://magecomp.com/blog/wp-content/uploads/2019/04/How-to-Add-Product-To-Cart-With-Custom-Price-in-Magento-2-1024x512.webp)

**Hello, Magento Friends!**

Magento Custom Development is a must-have for any business to fill the needs and save time and efforts to serve an excellent shopping experience to the shoppers. With the aid of smooth modifications and amalgamations in the frontend as well as backend, the Magento 2 E-commerce can provide a first-class user experience where it allows the user to set the custom price while adding a product to the cart. We are making headway to appending a short fragment of code that can outweigh all the prices of products with your intended one.
## Introduction
Often, it happens that the store owner is willing to set a fixed product price even if multiple options/add-ons are selected by the customer from the front end for all or some specific products. At that time we need to manually code to override all store product prices with your desired custom price instead of manually editing all store products. Also, have a glance at the **[Magento 2 Custom Price Extension by MageComp](https://magecomp.com/magento-2-custom-price.html?utm_campaign=magento2customprice&utm_medium=blogbanner&utm_source=blog)** which enables the admin to set a product price and the customer to add their desired product price.
In this tutorial blog, we will be demonstrating how you can Add Product to Cart with the Custom Price in Magento 2. This action triggers the already calculated price by Magento and lets you add your customized price.
## 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.
**app\code\Vendor\Extension\etc\frontend\events.xml**

Now add the below code
```
<?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="checkout_cart_product_add_after">

     <observer name="customprice" instance="VendorExtensionObserverCustomprice" />

 </event>

</config>
```

**Step 2:** Now, we need one more file named **“Customprice.php”** that overrides our price. Go to the below path
**app\code\Vendor\Extension\Observer\Customprice.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);

 }

}
```

That’s it!
## Bottom Line:
And, bingo! Hope everyone is now aware of How to Add Product To Cart With Custom Price in Magento 2. You are free to play and manipulate this according to your need for setting a custom price for one or more products by adding conditions. Also, get the [**Magento Custom Extension Development Service**](https://magecomp.com/magento-custom-extension-development.html) and custom develop your Magento store as per your business needs.
Let us know by commenting below if you are facing any issues during the implementation of this code.
**Happy Coding!**[![Magento Store](https://magecomp.com/blog/wp-content/uploads/2019/04/Magento-Store.png)](https://magecomp.com/magento-custom-extension-development.html)


---

_View the original post at: [https://magecomp.com/blog/add-product-to-cart-with-custom-price-magento-2/](https://magecomp.com/blog/add-product-to-cart-with-custom-price-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-09-28 21:09:06 UTC_  
