0

Is there a way to make SKU show on the Category page?

2 Answers 2

1

as Pawan says, you must override template file in your custom theme:

vendor/magento/module-catalog/view/frontend/templates/product/list.phtml

to

app/design/frontend/{Package}/{my-theme}/Magento_Catalog/templates/product/list.phtml

Then, you can show product SKU for example just after Product Name.

Look for this code:

<strong class="product name product-item-name">
    <a class="product-item-link" href="<?= $escaper->escapeUrl($_product->getProductUrl()) ?>">
        <?=/* @noEscape */ $_helper->productAttribute($_product, $_product->getName(), 'name') ?>
    </a>
</strong>

Final result would be:

<strong class="product name product-item-name">
    <a class="product-item-link" href="<?= $escaper->escapeUrl($_product->getProductUrl()) ?>">
        <?=/* @noEscape */ $_helper->productAttribute($_product, $_product->getName(), 'name') ?>
    </a>
</strong>
<p class="product-sku">
    <?php echo $_product->getSku(); ?>
</p>

Hope it helps :)

4
  • Thank you so much! Commented Apr 12, 2023 at 13:23
  • One more question if you do not mind. I'm trying to get it to say "SKU" in front of the SKU, but can't figure it out. Commented Apr 12, 2023 at 19:35
  • <p class="product-sku"> <?= $escaper->escapeHtml(__('SKU: ')) ?><?php echo $_product->getSku(); ?> </p> Commented Apr 13, 2023 at 11:21
  • Thanks, it woks, however, it only works on one of the servers. We have 2 servers; for some reason, it does not work for the other one. They both use Porto theme. Commented Apr 13, 2023 at 23:15
1

First override template file in theme, if it not exist.

vendor/magento/module-catalog/view/frontend/templates/product/list.phtml

to

app/design/frontend/{Package}/{my-theme}/Magento_Catalog/templates/product/list.phtml

in foreach loop add below code to get sku, where you want.

<?php echo $_product->getSku(); ?>
3
  • What do you mean by "for each loop"? Commented Apr 10, 2023 at 16:49
  • means where you have access to product object.you can add above code below product name as well.
    – Pawan
    Commented Apr 11, 2023 at 2:40
  • Sorry, i'm not 100% sure what you mean. Could you please show me an example or something? Commented Apr 11, 2023 at 11:04

Your Answer

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

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