Skip to content

Customization Example - adding "Old Price" on the listing page

Add a second price field to your Vehica listings and show the old price struck through beside the current one — on the single listing page with the page builder, and on the listing cards with a short PHP snippet.

2 minute read

In this article we create an “Old Price” field and show it on the listing page, so visitors can see at a glance what a listing used to cost. The second half shows how to put the same price on the listing card, which needs a small PHP customization.

1. Create the Old Price field and add it to a sample listing

  1. 1 Create a new “Old Price” field

    In Vehica Panel > Custom Fields, name the field Old Price and give it the Price type.

    Vehica Panel Custom Fields with “Old Price” typed into the Add new field box, the type select set to Price, and arrows pointing at both and at the ADD NEW FIELD button.
  2. 2 Move the field next to the current price

    Drag it in the field list so it sits beside the existing price field.

  3. 3 Edit a sample listing The listing list in WordPress with the row actions open under “BMW 8-serie 2-door coupe grey” — Edit, Quick Edit, Trash, View, Duplicate — and the pointer near Edit.
  4. 4 Fill in both prices The listing's field boxes with Price (USD) set to 62000 and Old Price (USD) set to 98000, next to Make BMW, Model 8-Serie and Year 2021.
  5. 5 Save the listing The WordPress Publish panel of the listing — Status: Published, Visibility: Public — with the pointer on the Update button.

2. Show the Old Price on the single listing template

The old price is a field like any other, so it goes on the page through the single listing template — the template Vehica uses to render an individual listing.

Vehica Panel > Layouts & Templates listing the Listing Page Template, Search Results Template, User Page Template, Post Page Template and Blog Page Template, with the “Edit using page builder” tooltip over the Listing Page Template's EDIT button.

Pick a preview listing that has the Old Price field filled in, so you can see what you are styling.

The listing page template open in Elementor, previewing “BMW 8-serie 2-door coupe grey” at $62,000, with the preview-listing settings highlighted in the left panel.

Duplicate the price element on the desktop design: right-click it and choose Duplicate. The copy becomes the old price.

Elementor's right-click menu over the $62,000 price element, with Duplicate (Ctrl+D) hovered, above Copy, Paste, Paste style, Reset style, Navigator and Delete.

On the copy, set Field to Old Price and style it — in the example it is struck through and greyed out.

The duplicated element with its Field set to Old Price: the preview now shows $98,000 struck through in grey in front of the orange $62,000.

Repeat the same change for the tablet and mobile designs.

The same template in Elementor at a narrower device width, with $98,000 struck through in front of $62,000 under the listing photo.

Save your changes.

Close-up of Elementor's bottom bar with the pointer on the UPDATE button.

3. Add the Old Price to the card

The card is not built in the page builder, so the old price cannot be added there without editing a PHP file. This part needs basic knowledge of HTML, CSS and PHP. If you have it, follow the steps below.

Keep your PHP changes in a child theme
Anything you edit inside the theme folder is overwritten by the next update. Copy the file into your child theme first — see How to use Child Theme? How to change files (php / css / js) and keep theme future update compatibility?

A. Open the price field for editing and read its ID out of the address bar.

Vehica Panel Custom Fields with the field table — Condition, Type, Make, Model, Price, Old Price — and an arrow pointing at the EDIT button on the Old Price row.
The Old Price field settings (field type: Price). The address bar reads /wp-admin/admin.php?page=vehica_22742&vehica_type=field, with an arrow on the number; the site domain is blurred out.

In our example it is 22742. Write it down — you will need it later.

B. The listing cards all live in /wp-content/themes/vehica/templates/card/car/, as shown below.

A code editor file tree: wp-content > themes > vehica > templates > card > car, containing card_big_v1.php, card_big_v2.php, card_big_v4.php, card_v1.php, card_v2.php (selected), card_v3.php, card_v4.php and card_v5.php.

C. Open the card you want to change — for example the card with a white background, card_v2.php — and add this code:

card_v2.php
<?php
            $priceField = vehicaApp('price_fields')->find(static function ($priceField) {
                return $priceField->getId() === 22742; // 22742 is the ID of the price field
            });
            if ($priceField instanceof \Vehica\Model\Post\Field\Price\PriceField) :
                $price = $priceField->getFormattedValueByCurrency($vehicaCurrentCar);
                if (!empty($price)) : ?>
                    <span style="
                        font-size: 16px;
                        text-decoration: line-through;
                        color: purple;
                        font-weight: 700;
                        position: relative;
                        top: -6px;
                    ">
                    <?php echo esc_html($price); ?>
                    </span>
                <?php endif;
            endif;
            ?>

Change 22742 to your own price field ID and adjust the styling to your needs. In our example it comes out like this:

Inventory with 11 results. The first card, “BMW 8-serie 2-door coupe grey”, shows $62,000 with $98,000 struck through in purple underneath, and a $98,000 chip in the spec row below it.

Ask the people who build Vehica

We answer by email from support@tangiblewp.com. With Premium Support, we also fix your site when something breaks.

Was this guide helpful?