1

How to get the width of Product UoM in magento2

Ex: Weight : 100 cm

measurement

Thanks.

1
$product->getTsDimensionsLength();
$product->getTsDimensionsWidth();
$product->getTsDimensionsHeight();

or use this

$height = $_product->getResource()->getAttribute('ts_dimensions_height'); 
$Value = $height->getFrontend()->getValue($_product);
$width = $_product->getResource()->getAttribute('ts_dimensions_width'); 
$Value = $width->getFrontend()->getValue($_product);
$length = $_product->getResource()->getAttribute('ts_dimensions_length'); 
$Value = $length->getFrontend()->getValue($_product);
  • I want to get the unit of width ? – Mano M Mar 1 at 9:33
  • check updated code. – chandresh chauhan Mar 1 at 9:40
  • Its give only value not unit of length(cm) ... – Mano M Mar 1 at 10:23
  • shortest way you can do it manually like $width = $_product->getResource()->getAttribute('ts_dimensions_width'); $Value = $width->getFrontend()->getValue($_product) .'cm'; – chandresh chauhan Mar 1 at 11:01
  • Is it a proper way ? – Mano M Mar 1 at 11:04
0

You can get these values like below code

<?php if($product->getWidth()): ?>
    <b>Width:</b><?php echo $product->getWidth(); ?>
<?php endif; ?>

Or if you want to display these values in More Information tab then just update these attributes by go to Stores -> Attributes -> Product from left side menu.

Click on Attribute you want to display inside details page.

Now click on Storefront Properties tab from left sidebar, Set Yes on Visible on Catalog Pages on Storefront.

and Save Atribute and Clear cache

  • but i need to display "Width : 150 cm" ... how to get the unit of length(cm) – Mano M Mar 1 at 10:26

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.