Magento – How to add the product sku to the PDP page

magento-2.1PHP

I would like to add the sku to the pdp page right above "Color". I have narrowed down my html template search to the file vendor/magento/module-catalog/view/frontend/templates/product/view/options/wrapper.phtml

<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
?>
<?php
$required = '';
if ($block->hasRequiredOptions()) {
    $required = ' data-hasrequired="' . __('* Required Fields') . '"';
}
?>
<div class="product-options-wrapper" id="product-options-wrapper"<?php /* @escapeNotVerified */ echo $required; ?>>
    <div class="fieldset" tabindex="0">
        <?php echo $block->getChildHtml('', true);?>
    </div>
</div>

I can not figure out though where $block-getChildHtml('', true); is grabbing the html from for me to edit that page?

UPDATE

The layout that this template is using is at magento/module-catalog/view/frontend/layout/catalog_product_view.xml. If I remove all of the child blocks (options.phtml, text.phtml, file.phtml etc.), nothing changes. However if I remove the parent block (product.info.options.wrapper) the content does go away. So it seems the content is coming from the parent and not the children somehow.

<block class="Magento\Catalog\Block\Product\View" name="product.info.options.wrapper" as="product_options_wrapper" template="product/view/options/wrapper.phtml">
    <block class="Magento\Catalog\Block\Product\View\Options" name="product.info.options" as="product_options" template="product/view/options.phtml">
        <block class="Magento\Catalog\Block\Product\View\Options\Type\DefaultType" as="default" template="product/view/options/type/default.phtml"/>
        <block class="Magento\Catalog\Block\Product\View\Options\Type\Text" as="text" template="product/view/options/type/text.phtml"/>
        <block class="Magento\Catalog\Block\Product\View\Options\Type\File" as="file" template="product/view/options/type/file.phtml"/>
        <block class="Magento\Catalog\Block\Product\View\Options\Type\Select" as="select" template="product/view/options/type/select.phtml"/>
        <block class="Magento\Catalog\Block\Product\View\Options\Type\Date" as="date" template="product/view/options/type/date.phtml"/>
    </block>
    <block class="Magento\Framework\View\Element\Html\Calendar" name="html_calendar" as="html_calendar" template="Magento_Theme::js/calendar.phtml"/>
</block>

enter image description here

Best Answer

Depending on the option type, it uses one of the phtml files under

vendor/magento/module-catalog/view/frontend/templates/product/view/options/type

or

 vendor/magento/module-configurable-product/view/frontend/templates/product/view/type/options/configurable.phtml

and to get the product sku just call

$block->getProduct()->getSku();
Related Topic