Step 1: Create di.xml file in etc/frontend. Put below content in it.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCatalogModelProduct">
<plugin name="change_product" type="MagemonkeysChangepricePluginChangeProductPrice" sortOrder="1" disabled="false" />
</type>
</config>
Step 2: Create di.xml file in etc/webapi_rest. Put below content in it.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCatalogModelProduct">
<plugin name="change_product" type="MagemonkeysChangepricePluginChangeProductPrice" sortOrder="1" disabled="false" />
</type>
</config>
If you add this plugin only in front-end area then the change price functionality will not work on checkout and cart page. So you have to create another di.xml file in etc/webapi_rest folder.
Step 3: Create Plugin Folder and Create ChangeProductPrice.php in it. Put Below content in it.
<?php
namespace MagemonkeysChangepricePlugin;
class ChangeProductPrice
{
public function afterGetPrice(MagentoCatalogModelProduct $subject, $result)
{
/* Put your logic here and return the $result */
return $result+10;
}
}
Step 4: After that run the upgrade, compile, static-content deploy and flush cache command through the terminal as below. And you can check now.
php -dmemory_limit=6G bin/magento setup:upgrade php -dmemory_limit=6G bin/magento setup:di:compile php -dmemory_limit=6G bin/magento setup:static-content:deploy -f php -dmemory_limit=6G bin/magento cache:flush

