Display Old Price Struck-Through Next to New Promotional Price
Explanation
To show the old price with a strikethrough next to the new sale price in WooCommerce, this code snippet does the trick:
What It Does:
- Checks if a product is on sale.
- Grabs both the regular (old) price and the sale (new) price.
- Formats the old price with a strikethrough and places it next to the new price.
How It Works:
- The code hooks into WooCommerce's price display system.
- If the product is on sale, it fetches both the regular and sale prices.
- The regular price is wrapped in a
<del>tag, which adds the strikethrough effect. - The sale price is wrapped in an
<ins>tag, making it stand out.
Result: On your product pages, customers will see the original price crossed out, right next to the discounted price, making it clear there's a sale.
Code
Instructions
File Location: Add the code to your theme's functions.php file or a custom plugin file.
Prerequisites:
- Ensure WooCommerce is installed and activated on your WordPress site.
Implementation Steps:
- Log in to your WordPress admin dashboard.
- Navigate to Appearance > Theme Editor.
- In the right-hand sidebar, find and click on
functions.phpto open it. - Scroll to the bottom of the
functions.phpfile. - Copy and paste the provided code snippet at the end of the file.
- Click Update File to save your changes.
- Visit a product page on your site to verify that the old price is displayed with a strikethrough next to the new sale price.
If you encounter any issues or need further customization, consider reaching out to wp-dude.com for expert assistance.