1

How to get the width of Product UoM in magento2

Ex: Weight : 100 cm

measurement

Thanks.

2 Answers 2

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);
8
  • I want to get the unit of width ?
    – Mahi M
    Mar 1, 2019 at 9:33
  • check updated code. Mar 1, 2019 at 9:40
  • Its give only value not unit of length(cm) ...
    – Mahi M
    Mar 1, 2019 at 10:23
  • shortest way you can do it manually like $width = $_product->getResource()->getAttribute('ts_dimensions_width'); $Value = $width->getFrontend()->getValue($_product) .'cm'; Mar 1, 2019 at 11:01
  • Is it a proper way ?
    – Mahi M
    Mar 1, 2019 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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.