2

I've tried multiple snippets of code to add an item price to a specific block without success.

On the example item page :

https://fixlcdscreens.com/default/catalog/product/view/id/10234/s/ACER-ASPIRE-V5-571-6868-15.6%22-Laptop-LCD-LED-Display-Screen/

I would like to add the product price in the right column block where I have put the text [INSERT PRICE HERE]

The following result happens from entering this code:

$this->getPriceHtml($_product, true);

enter image description here

The next snippet of code here results in the following :

<?php
    $productBlock = new Mage_Catalog_Block_Product;
    echo $productBlock->getPriceHtml($_product);
    ?>

enter image description here

Can someone please help me achieve this in what you believe is the simplest way. For reference I am trying to add the price (not move the original) to the block identifier : block_product_secondary_bottom

1
  • You're calling PHP code in a static block? That won't work. Unless you are Ok to hard-code price in the block, you'll need to call a template atleast to display the prices.
    – Prateek
    Commented Dec 22, 2016 at 4:41

1 Answer 1

0

you can not directly add the php code in the cms-block.

But you can call template and with in that template you can add php code. and create template app/design/frontend/YourPackage/YourTheme/template/Yourtemplatepath/yourTemplate.phtml

add this code

{{block type="core/template"  template="Yourtemplatepath/yourTemplate.phtml" }}

and add below code in template file yourTemplate.phtml file

<?php
$product = Mage::registry('current_product');
$block = $this->getLayout()->createBlock('catalog/product_price');
echo $block->getPriceHtml($product);
?>
6
  • @d0pamine try this code and let me know and if its working for you then mark as accepted this answer , though I have tested this code and working fine for me. Commented Dec 22, 2016 at 6:37
  • Hi thanks for the reply, I added the code to literally yourTemplate.phtml , and added the file to /Yourtemplatepath/yourTemplate.phtml ... but it is just showing the code in the file directly , check this page : fixlcdscreens.com/default/catalog/product/view/id/8226/s/…
    – d0pamine
    Commented Dec 22, 2016 at 6:39
  • @d0pamine add php tag please check my updated answer Commented Dec 22, 2016 at 6:41
  • @d0pamine add <?php tag in phtml file before the code and add ?> tag in end of the file , check my updated answer Commented Dec 22, 2016 at 6:44
  • EXCELLENT! WORKED! -- Can I ask you before I hit answered (in case it closes the post, can you tell me if I can add a line in the code to change the color/size of the price text?
    – d0pamine
    Commented Dec 22, 2016 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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