app/module/vendor/View/layout
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:
noNamespaceSchemaLocation=
"urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info.main">
<block class="SegaProductHeightBlockProductHeight"
template="Sega_ProductHeight::height.phtml" cacheable="false"/>
</referenceBlock>
</body>
</page>
app/module/vendor/View/template
test
module/vendor/Block
<?php
namespace SegaProductHeightBlock;
use MagentoCatalogModelProduct;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkRegistry;
use MagentoFrameworkViewElementTemplate;
class ProductHeight extends Template
{
protected $registry;
protected $product;
public function __construct(
TemplateContext $context,
Registry $registry,
array $data)
{
$this->registry = $registry;
parent::__construct($context, $data);
}
public function getProduct()
{
if (is_null($this->product)) {
$this->product = $this->registry->registry('product');
if (!$this->product->getId()) {
throw new LocalizedException(__('Failed to initialize product'));
}
}
return $this->product;
}
public function getProductHeight()
{
return $this->getProduct()->getData('product_height');
}
}