cancel
Showing results for 
Search instead for 
Did you mean: 

product attribute php code help

product attribute php code help

Hi all.....

Coming from a Microsoft ASP background, I'm not familiar with the Syntax of PHP. and hope you guys can help me out.

I've created a product attribute with a yes/no value.

Placing <?php echo $_product->getAttributeText('pricematch') ?> on the product page does work and correctly displays, yes or no depending on the attribute (pricematch) setting in the admin.

However, i want to display an icon image if the value is yes and display nothing if the value is no.

A very simple 'IF' statement.

I've tried a few variations of the belwo to no avail.

I'm sure someone will have the answer, so thank you in advance

 

Andy

 

<?php if (($_product->getAttributeText('pricematch'))=true) {
            echo "Hello"; }
}
?>
2 REPLIES 2

Re: product attribute php code help

Sorted it guys - :-)

php seems very picky with capitalization

 

Thanks again

 

Re: product attribute php code help

Hello,

 

Seem that you use Magento 1.9.x version. If you use Magento 1.9.x, there are two options:

+If we use getAttributeText('pricematch') => this will return Yes or No text.

<?php
if ($_product->getAttributeText('pricematch')== 'Yes') {
echo "Hello";
}
?>

 

+If we use getPricematch() => this will return 0 (no or null default) or 1 (yes) value. This way is sort and clear. We should use this way.

<?php
if ($_product->getPricematch()) {
echo "Hello";
}
?>

Problem solved? Click Accept as Solution!