Magento2 – How to Change Position of Regular Price and Special Price in Product Detail Page

magento2

I overriden product/price/amount/default.phtml file

<span class="price-container <?php /* @escapeNotVerified */ echo $block->getAdjustmentCssClasses() ?>"
    <?php echo $block->getSchema() ? ' itemprop="offers" itemscope itemtype="http://schema.org/Offer"' : '' ?>>
    <?php if ($block->getDisplayLabel()): ?>
        <span class="price-label">
            <?php /* @escapeNotVerified */ echo $block->getDisplayLabel(); ?>
        </span>
    <?php endif; ?>
        <span <?php if ($block->getPriceId()): ?> id="<?php /* @escapeNotVerified */ echo $block->getPriceId() ?>"<?php endif;?>
            <?php echo($block->getPriceDisplayLabel()) ? 'data-label="' . $block->getPriceDisplayLabel() . $block->getPriceDisplayInclExclTaxes() . '"' : '' ?>
            data-price-amount="<?php /* @escapeNotVerified */ echo $block->getDisplayValue(); ?>"
            data-price-type="<?php /* @escapeNotVerified */ echo $block->getPriceType(); ?>"
            class="price-wrapper <?php /* @escapeNotVerified */ echo $block->getPriceWrapperCss(); ?>"
            <?php echo $block->getSchema() ? ' itemprop="price"' : '' ?>>
            <?php /* @escapeNotVerified */ echo $block->formatCurrency($block->getDisplayValue(), (bool)$block->getIncludeContainer()) ?>
        </span>
    <?php if ($block->hasAdjustmentsHtml()): ?>
    <?php echo $block->getAdjustmentsHtml() ?>
    <?php endif; ?>
    <?php if ($block->getSchema()): ?>
    <meta itemprop="priceCurrency" content="<?php /* @escapeNotVerified */ echo $block->getDisplayCurrencyCode()?>" />
    <?php endif; ?>
</span>

Best Answer

You can change position by overriding the file /var/www/html/magento2/vendor/magento/module-catalog/view/base/templates/product/price/final_price.phtml

    <?php if ($block->hasSpecialPrice()): ?>
        <span class="special-price">
            <?php /* @escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
                'display_label'     => __('Special Price'),
                'price_id'          => $block->getPriceId('product-price-' . $idSuffix),
                'price_type'        => 'finalPrice',
                'include_container' => true,
                'schema' => $schema
            ]); ?>
        </span>
        <span class="old-price">
            <?php /* @escapeNotVerified */ echo $block->renderAmount($priceModel->getAmount(), [
                'display_label'     => __('Regular Price'),
                'price_id'          => $block->getPriceId('old-price-' . $idSuffix),
                'price_type'        => 'oldPrice',
                'include_container' => true,
                'skip_adjustments'  => true
            ]); ?>
        </span>
    <?php else: ?>
        <?php /* @escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
            'price_id'          => $block->getPriceId('product-price-' . $idSuffix),
            'price_type'        => 'finalPrice',
            'include_container' => true,
            'schema' => $schema
        ]); ?>
    <?php endif; ?>

Changed it to the following

<?php if ($block->hasSpecialPrice()): ?>

    <span class="old-price">
        <?php /* @escapeNotVerified */ echo $block->renderAmount($priceModel->getAmount(), [
            'display_label'     => __('Regular Price'),
            'price_id'          => $block->getPriceId('old-price-' . $idSuffix),
            'price_type'        => 'oldPrice',
            'include_container' => true,
            'skip_adjustments'  => true
        ]); ?>
    </span>

     <span class="special-price">
        <?php /* @escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
            'display_label'     => __('Special Price'),
            'price_id'          => $block->getPriceId('product-price-' . $idSuffix),
            'price_type'        => 'finalPrice',
            'include_container' => true,
            'schema' => $schema
        ]); ?>
    </span>
<?php else: ?>
    <?php /* @escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
        'price_id'          => $block->getPriceId('product-price-' . $idSuffix),
        'price_type'        => 'finalPrice',
        'include_container' => true,
        'schema' => $schema
    ]); ?>
<?php endif; ?>

Hopefully it will help you.