0

I have added a product with special price, Template is already showing special price with original price strike through over it

enter image description here

I want to show special price start and end dates beneath product price, how to achieve this

I have tried this with custom theme to override price in My/CustomTheme/Magento_Catalog/layout/catalog_product_view.xml in a hope it will show my template underneath product.info.price of the original applied theme

<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
    <referenceContainer name="content">
      <block class="Magento\Catalog\Block\Product\View" name="product.info.price.special.dates" after="product.info.price" template="special.phtml">
    </referenceContainer>
  </body>
</page>

and will show dates in special.phtml

3
  • Use these function: $product->getSpecialFromDate() //Start date $product->getSpecialToDate() // End Date
    – D Singh
    Apr 23, 2018 at 8:43
  • where should I do this is the question Apr 23, 2018 at 8:52
  • In special.phtml file
    – D Singh
    Apr 23, 2018 at 9:13

1 Answer 1

0

I did this by creating a module rather,

with view file //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>
    <referenceContainer name="product.info.price">
      <block class="Vendor\Module\Block\SpecialPrice" name="special_price_dates" after="product.price.final"/>
    </referenceContainer>
    <referenceBlock name="special_price_dates">
      <action method="setTemplate">
        <argument name="template" xsi:type="string">special_price.phtml</argument>
      </action>
    </referenceBlock>
  </body>
</page>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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