1

I wish to add a simple span class on the product view page for the price.

<span class="price-symbol">$</span>
<span class="price">$99.90</span>
2
  • Can you be more specific on what all product types you need to add class ?
    – Roney
    Commented Sep 16, 2014 at 15:52
  • Hello Roney, thanks for your help. It's for all product types.
    – phpschool
    Commented Sep 16, 2014 at 16:01

4 Answers 4

1

if you are looking for quick hack then above mentioned method will do the trick. I recommend to override your theme price.phtml and reference handle [catalog_product_view] like below adding your custom price_pdp.phtml in your theme local.xml

Eg:

 <catalog_product_view>
    <reference name="catalog_product_price_template">            
        <action method="addPriceBlockType">
            <type>simple</type>
            <block>catalog/product_price</block>
            <template>catalog/product/price_pdp.phtml</template>
        </action>
        <action method="addPriceBlockType">
            <type>configurable</type>
            <block>catalog/product_price</block>
            <template>catalog/product/price_pdp.phtml</template>
        </action>

      ......
    </reference>  
</catalog_product_view>
1
  • Thanks Roney, it's working for me but I seek another fastest solution way to add a simple class. Have you any other ideas ?
    – phpschool
    Commented Sep 16, 2014 at 16:36
3

You need to alter the catalog/product/price.phtml template file, adding the following in several places (for each instance you see of <span class="price">...):

<span class="price-symbol"><?php echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol(); ?></span>

This will get the symbol for the currently selected currency.

0

Pm

Go to this file: Depend upon which theme you are using.

app/design/frontend/custom_theme/default/template/catalog/product/price.phtml

or

app/design/frontend/base/default/template/catalog/product/price.phtml

0

In magento 2 it can be done by using jquery in phtml file

<?php 
$objectManager =\Magento\Framework\App\ObjectManager::getInstance(); 
$currencysymbol = $objectManager->get('Magento\Store\Model\StoreManagerInterface');
 $currency_symbol = $currencysymbol->getStore()->getCurrentCurrencyCode(); ?>
<script>
require(['jquery', 'jquery/ui'], function($){
    $('.product-info-price').bind('DOMSubtreeModified', function(){

        if($(this).find('.symbol').length == 0) {
             $("span.price").each(function() {
                $(this).html($(this).html().replace("<?php echo $currency_symbol ?>","<span class='symbol'><?php echo $currency_symbol ?></span>"));
            });
        }
    });
});
</script>

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