Hey I am very new to PHP, I come from a design background, but I am now trying to figure out some of the PHP myself.
I have a problem with a if else statement where I would like users to register to view product prices (Logged in users can view prices, but other users are presented with a ‘please register’ blurb). But I can’t figure out how to get the register URL to echo inside the a href tag.
Here is my code:
<?php if (Mage::getSingleton('customer/session')->isLoggedIn()) {
echo $this->getPriceHtml($_product, true);} else { echo '<a href="#">Please register to view prices</a>';}
?>
<?php echo Mage::helper('persistent')->getCreateAccountUrl($this->getCreateAccountUrl()) ?>
The code on the bottom is used to call the register URL. I can’t figure out how to properly place the register URL code into the a href tags without it generating some sort of error. Can anyone help?
Try this code. Basically you want to join strings together. Mage::helper… returns a string. So join that result with the static string which includes your html for a link.
Bit to deep for this question but really I would not use echo to display any html. Where possible just use php to display dynamic content. e.g.