I show product reviews based on SKU. what I want is to use the sku of an attribute but if that attribute is empty use another.

For Example:

echo $_product->getwildcardSKU_attribute
if( wildcardSKU_attribute = empty ){
echo $_product->getSKU_attribute

I know my code makes no sense but it is just an example.

This is the code I need to use it in.

<?php echo $this->__('<img src="https://www.someURL.com=' . $_product->getwildcardsku() . '" alt="">') ?>
  • what your attribute code?
    – Amit Bera
    Mar 31, 2016 at 11:17
  • 1
    @arunendra is right. follow that code.
    – Ajay Patel
    Mar 31, 2016 at 11:24
  • a code like that just can't work function are getWildCardSku() or getData('wild_card_sku') assuming that wild_card_sku is the name of the attribute. you have an affectation instead of comparison in your if, empty() does what you need and a $ is missing for the variable. Moreover, the helper class "catalog/output" as a function productAttribute that should be used to prepare the attribute for front display. Mar 31, 2016 at 11:25
  • I cannot seem to use the code as the page breaks when i try and echo inside the code Im using Mar 31, 2016 at 11:56

2 Answers 2


You can use something like this:

Exp: Suppose your attribute code is : wild_cards_sku

then you can get it using below code:

 $wildCardSku = $_product->getWildCardsSku();
    $wildCardSku = $_product->getSku();
  echo $this->__('<img src="https://www.someURL.com=' . $wildCardSku. '" alt="">');
  • Thanks but how could it work in my code. Please see my updated question Mar 31, 2016 at 11:43
  • I have updated answer
    – Arunendra
    Mar 31, 2016 at 12:00
echo empty($_product->getWildcardskuSku) ? $_product->getSku() : $_product->getWildcardskuSku();

Please note that : $_product->getwildcardSKU_attribute() is not correctly written. Please correct this to $_product->getWildcardskuSku()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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