0

I have a phtml file that needs to load the weight unit of the product, the weight unit is from the store configuration, is there a way to do this?

1

If you have the product loaded inside your custom phtml file, you can use:

$weight = $product->getData('weight');
1

For product weight unit. Try this -

You need to use the instance of \Magento\Framework\App\Config\ScopeConfigInterface in your block:

Create the method getWeightUnit()

public function getWeightUnit()
{
    return $this->_scopeConfig->getValue(
        'general/locale/weight_unit',
        \Magento\Store\Model\ScopeInterface::SCOPE_STORE
    );
}

and call in your template echo $this->getWeightUnit();

  • .how to get the width unit in magento2 .... – Mano M Mar 1 at 10:39
  • Thanks! Tried this one and it worked! – MazeStricks Oct 25 at 7:14

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.