cancel
Showing results for 
Search instead for 
Did you mean: 

How to display html content of custom option in magento 2.3

SOLVED

How to display html content of custom option in magento 2.3

Hello Everyone,

I'm stuck with with a problem please help.

I'm trying to add an html code on product custom option in admin with type selected as radio button. But when I save the product it simply takes the html code as string and displays the html content. 
Please check the screenshot: https://prnt.sc/ukl0km
Please help me!

Thanks in advance. 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to display html content of custom option in magento 2.3

Found a solution!

I've used php html_entity_decode() function to get the html content.
I've made changes in vendor/magento/module-catalog/view/base/templates/product/composite/fieldset/options/view/checkable.phtml file.

<span>
<?php
$str = $block->escapeHtml($value->getTitle());

?>
<?php echo html_entity_decode($str);?>
<!-- <?= $block->escapeHtml($value->getTitle()) ?> --> //comment this line
</span>
this solved my problem. Smiley Happy

View solution in original post

5 REPLIES 5

Re: How to display html content of custom option in magento 2.3

Hello @mamun_paul 

 

The product custom options are supposed to take only string values, you can't put anything in custom option, I guess you want to acknowledge customer about the colour details.

You can add HTML code as additional information in product description which you can find in same product edit section :

Catalog > Products > Choose Product > Edit > Content

 

Hope it helps !

 

Problem Solved ? Click on 'Kudos' & Accept as Solution ! Smiley Happy

Re: How to display html content of custom option in magento 2.3

Thanks for your reply.
I wanted a custom option where on click of the option the user will redirect to the product.
I can give you an example which have the same functionality but its in M1
Please check this: https://www.froothie.com.au/optimum-9200a-2nd-gen
Please check the screenshot as well: https://prnt.sc/ukwe8a


Re: How to display html content of custom option in magento 2.3

Found a solution!

I've used php html_entity_decode() function to get the html content.
I've made changes in vendor/magento/module-catalog/view/base/templates/product/composite/fieldset/options/view/checkable.phtml file.

<span>
<?php
$str = $block->escapeHtml($value->getTitle());

?>
<?php echo html_entity_decode($str);?>
<!-- <?= $block->escapeHtml($value->getTitle()) ?> --> //comment this line
</span>
this solved my problem. Smiley Happy

Re: How to display html content of custom option in magento 2.3

Thank you! working for me

Re: How to display html content of custom option in magento 2.3

Instead of making the changes in the core file, please override the html in your custom module and do the changes.