0

Hi i would like to change my product price dynamically while change the custom option text field value.

I have written the code as shown below

app/design/frontend/Smartwave/porto/Magento_Catalog/templates/product/view/options/wrapper.phtml

<script>
require(["jquery","Magento_Catalog/js/price-utils"],
function(jQuery,priceUtils) {
var finalPrice=500;
var formatedPrice = priceUtils.formatPrice(finalPrice);
jQuery('span.price-final_price > span.price-wrapper >span.price').text(formatedPrice); 
});  
</script>
4

1 Answer 1

1

I found a solution The below script has been written in the template file (wrapper.phtml)

app/design/frontend/Smartwave/porto/Magento_Catalog/templates/product/view/options/wrapper.phtml


    <script type="text/javascript">
    require(['jquery','Magento_Catalog/js/price-utils','jquery/ui'], function ($,priceUtils) 
    {
     $(document).ready(function(){

        $('.CabWidth').on('change', function(){ 

        var finalPrice='200.55';
        formatedPrice = priceUtils.formatPrice(parseFloat(finalPrice));
        jQuery('span.price-final_price > span.price-wrapper > span.price').text(formatedPrice);
        finalPrice=(pricePerText*textObjects)+(pricePerImage*imageObjects);
        formatedPrice = priceUtils.formatPrice(parseFloat(finalPrice));
        jQuery('span.price-final_price > span.price-wrapper > span.price').text(formatedPrice);    

        });
    });

    });
    </script>

Note: Magento2rootFolder/vendor/magento/module-catalog/view/base/web/js/price-utils.js copied and pasted to below path

Magento2rootFolder/app/design/frontend/Smartwave/porto/Magento_Catalog/web/js/price-utils.js
1
  • What is pricePerText and pricePerImage in your code? Commented Mar 5, 2020 at 7:13

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