Is there a way to show the value of a custom attribute that changes for every child product?
I mean something like: user selects "blue" color for shirt and, under the swatches a text appears (like, say, "you selected blue").
I did this (catalog_product_view.xml):
<?xml version="1.0"?> <body> <referenceContainer name="product.info.main"> <block class="Frostmage\Attrishow\Block\Product\View\Extra1" name="product.view.extra1" template="Frostmage_Attrishow::product/view/extra1.phtml" before="product.price.tier"> </block> </referenceContainer> </body>
and this (extra1.phtml):
<?php $_product = $block->getProduct() ?> <h3 style="font-size: 1em; color: black;"> <?php $ciao = $_product->getData('entitacanone'); echo 'Canone Mensile: <span style="font-size: 2em; color: #FF8A00;">'.$ciao.'€</span>'; echo '<span>/mese</span>'; ?></h3>
But, obviously, it doesn't change the frontend text based on the product variation, it only shows the value of the parent product, if it has one. I assume there is some kind of js to add, but I don't know how or what...
Any clue? Thanks :)