How To Update Magento 2 Product Price Programatically

How can I update Magento 2 product’s price programatically

You need to load the product object first and call “setPrice” method to update the price of Magento 2 product

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product_id = 1;
$price = "20.12";
$productFactory = $objectManager->get('\Magento\Catalog\Model\ProductFactory');
$product = $productFactory->create()->load($product_id);
$product->setPrice($price);
$product->save();
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments