0

I've created a product attribute in the admin panel and have added it to a product. These attributes are now showing within the tabs on the frontend, however I would like them to appear between the product short description and the SKU.

I've added the following code in the correct location within view.phtml, and this is showing correctly on the frontend if only one option is selected

<?php echo $_product->getAttributeText('product_use'); ?>

However if there are multiple items selected then the only thing that will show up on the front end is the word array

0

It depends on how you have managed the select attribute from backend, If the managed data type is an array, then While fetching the data on front end you will have to use "foreach" Use this below example to display multi select data,

if ($multiSelectArray = $_product()->getAttributeText('product_use')) {
    if (is_string($multiSelectArray)) {
    $multiSelectArray = array($multiSelectArray);
    }
    foreach ($multiSelectArray as $multiSelectItem) :
   //add your code here.
    endforeach;
}
  • 2
    That's excellent, thank you very much for your help! – KnightlyWebGuy Jun 7 '19 at 8:15

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.