I am trying to create a Express Entry Detail template and wonder if anyone can help with php code to output a Option List with multi values so I can wrap each value in html code.
i.e. List is 'colour options available for product. SO I want the temple to output whichever colours are selected in separate Div to create sample swatch for each
Product 1 available in Red Green Blue
Product 2 available in Green
I want the template to output each colour as a
and the colour would be the css class for the div. I have tried lots of things without success. I get all colours inline. Any help would be much appreciated. Below how it works at the moment but obviously if the client wanted to add more colours I would have to amend the code rather than it working dynamically when new colours are added in Express
A lot of magic is happening behind the scenes when dealing with Select attribute. $product->getAttribute('colour') is actually iterable and it is also “magically” converted to string when being displayed/casted to string (echo method etc.).
You can loop through attribute as it was a normal array, for example:
Excellent! Thanks for coming back so quickly. I have spent hours trying work out a solution. Your solution works perfectly thank you very much appreciated. Great way to finish a Friday
Many thanks again
Hi me again. I was wondering if its possible to separate out values in an option list so that one part is a label and another is a css clas. I have done something similar in, sorry to swear lol, wordpress. I put a value in of “New Product : red” and then get it so when I selected the one option it changed the text on a css ribbon and also changed the colour. Hope that makes sense. I have attached a screenshot which I hope explains a little more.
You could just create another Select attribute (which would store colors separately) or just fill Select options the same as in Wordpress New Product : red (with separator).
You would then need to explode that attribute:
Thanks for all your help, I have almost got it working as I want it. For some reason the code is appearing even when there is no values in the option field. I puts the div and without the class and text label in (see screenshot). I thought the “if” would do the trick
Genius! Perfect! all working as it should, I was all sorts of code to make it work. Simple when you know how. Thank you so much for your help, really appreciated. Here is the whole code just incase its usefully to anyone else. Thanks again