Skip to content

How to display woocommerce sale price or regular price if there is no sale

In WooCommerce, you can display the sale price or regular price of a product using the following code snippet:

Example of displaying the sale price or regular price of a product in Woocommerce

php
<?php

global $product;
if ($product->is_on_sale()) {
  echo $product->get_sale_price();
} else {
  echo $product->get_regular_price();
}

You can add this code snippet to the template file of your theme where you want to display the price, such as content-single-product.php or woocommerce/single-product/price.php.

This code checks if the product is on sale, and if it is, it will display the sale price. If the product is not on sale, it will display the regular price.

Make sure to use the correct hooks and filters to place this code snippet in the right place.

Also, you can use the following code snippet to display the sale price with a strikethrough and the regular price instead of only one of them

Example of displaying the sale price with a strikethrough and the regular price in Woocommerce

php
<?php

global $product;
if ($product->is_on_sale()) {
  echo '<del>' . wc_price($product->get_regular_price()) . '</del>';
  echo '<ins>' . wc_price($product->get_sale_price()) . '</ins>';
} else {
  echo wc_price($product->get_regular_price());
}

Dual-run preview — compare with live Symfony routes.