Displaying Magento Special Prices Without Regular Pricing
As an e-commerce developer, one of the most common requests I receive is to modify product pricing displays in Magento. Recently, a client asked how to show only special prices without displaying regular prices on their product page.
Understanding the Magento Pricing System
Magento uses several pricing components that work together:
- Regular price: The base price of an item.
- Special price: A temporary price applied to a product, usually for promotional purposes.
- Tier prices: Price breaks based on quantity.
- Group prices: Different prices for different customer groups.
By default, Magento displays both the regular and special prices in the frontend. In this scenario, we need to modify the display to show only the special price when available.
Modifying Theme Files
To achieve this, we’ll need to override the product view template file located at app/design/frontend/[package]/[theme]/template/catalog/product/view.phtml.
-
Create a new catalog folder:
Navigate to your theme directory and create a new folder named
catalog. If it doesn’t exist. -
Copy the view.phtml file:
Inside the newly created
catalogfolder, copy theview.phtmlfile from the Magento base theme (usually located atvendor/magento/theme-frontend-blank). -
Modify the price display section:
Open your copied
view.phtmlfile and locate this code block:<span class="price-label">Regular Price:</span> <?php echo $this->getProductPriceHtml($_product, $includeTax) ?>Replace it with the following:
<?php if ($_product->isSaleable() && $_product->getSpecialPrice()): ?> <div class="special-price"> <span class="price-label">Special Price:</span> <?php echo $this->getProductPriceHtml($_product, $includeTax) ?> <img src="<?php echo $this->getViewFileUrl('Magento_Theme::images/sale.gif'); ?>" alt="Sale" /> </div> <?php endif; ?>Here, we’re checking if the product is salable and has a special price. If both conditions are true, it displays the special price along with a sale image.
Configuring Product Attributes
Before implementing this change, ensure that your products have properly configured attributes:
-
Set Special Price: In the Magento admin panel, navigate to
Catalog > Products, select a product, and go to thePricestab. UnderSpecial Price, enter the discounted price and choose an expiration date. -
Enable saleable status: Set
Statusunder theGeneraltab of each product toEnabled.
Conclusion
By following these steps, you can successfully modify your Magento theme to display only special prices without showing regular pricing on your product pages.
Remember that when working with template files, it’s always best practice to create a child theme and make modifications there. This ensures that your changes won’t be overwritten during theme updates.
If you’re looking for professional Magento development services or have any other e-commerce questions, feel free to reach out to us at Laravel Company.