0

I have following code which displays the price in Magento.

<?php echo $this->getPriceHtml($_product); ?>

I have to put this code inside echo instead and I can't get it to work.

I am trying

echo "$this->getPriceHtml ($_product)";

It just displays () on the page.

I tried other combinations and I can't come up with anything else. What am I doing wrong?

2 Answers 2

4

Using single quotes will prevent $vars to be interpreted:

echo '$this->getPriceHtml ($_product)';

Or escape the $ sign:

echo "\$this->getPriceHtml (\$_product)";

http://php.net/manual/en/language.types.string.php

Or if by echo-ing you mean that you want to get something like

The price is 123.00

then do:

echo "The price is {$this->getPriceHtml($_product)}";

or even :

echo sprintf("The price is %s", $this->getPriceHtml($_product));
Sign up to request clarification or add additional context in comments.

Comments

0

why not you are using this ?

$_product->getFinalPrice() or

if you want in formatted order then why you are not using this number_format($pr->getPrice(), 2)

and if you want price with currency format then you can use this also Mage::helper('core')->currency($pr->getPrice());

Hope it will help you. :)

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.