Try following code:
- app/code/[VendorName]/[ModuleName]/registration.php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'[VendorName]_[ModuleName]',
__DIR__
);
- app/code/[VendorName]/[ModuleName]/etc/module.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="[VendorName]_[ModuleName]" setup_version="1.0.0">
<sequence>
<module name="Magento_Catalog"/>
</sequence>
</module>
</config>
- app/code/[VendorName]/[ModuleName]/view/frontend/layout/catalog_product_view.xml
<?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.details">
<block class="Magento\Catalog\Block\Product\View" name="custom.tab" template="[VendorName]_[ModuleName]::product/view/details/custom_tab.phtml" group="detailed_info">
<arguments>
<argument translate="true" name="title" xsi:type="string">Tab Title</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
- app/code/[VendorName]/[ModuleName]/view/frontend/templates/product/view/details/custom_tab.phtml
<?php $attributeCode = '<product_attribute_code>'; ?>
<?php echo $block->getProduct()->getData($attributeCode); ?>
Note:
Add your html code in "if" condition, if html data found in tab content then tab will be display on the product page.