Is there a way to make SKU show on the Category page?
2 Answers
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 :)
-
-
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
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(); ?>
-
-
means where you have access to product object.you can add above code below product name as well.– PawanCommented 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