Question

our product has SKU and P/N number. All product's SKU has the same, but the P/N will depend on the country, so I've created an attribute "P/N" and want to show P/N on the product page instead of SKU.

It is possible to replace SKU on the frontend with P/N?

can anyone help me with this?

Was it helpful?

Solution

Note: I have not tried it yet but it should work.

To show the SKU value in the product view page, /vendor/magento/module-catalog/view/frontend/templates/product/view/attribute.phtml file is called.

In this file you will find code like below:

$_call = $block->getAtCall();
$_code = $block->getAtCode();

which basically gets the values from the default catalog_product_view.xml file, there is a code block like below:

<arguments>
    <argument name="at_call" xsi:type="string">getSku</argument>
    <argument name="at_code" xsi:type="string">sku</argument>
    <argument name="css_class" xsi:type="string">sku</argument>
    <argument name="at_label" xsi:type="string">default</argument>
    <argument name="add_attribute" xsi:type="string">itemprop="sku"</argument>
</arguments>

You can override catalog_product_view.xml in your theme and change the values of at_call, at_code, css_class, at_label, and add_attribute as per your requirement.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top