Home Contact Us Payments SC Commerce SC Commerce Docs SC Commerce Snippets

Simply Computing

We make websites. Simple.

Show normal price, new price and savings

When an item is on sale, Classic Commerce normally just shows the regular price and the sale price. It can be helpful to also show how much the customer will be saving by using this code. You can style the message by using the included class “was-now-save”.

 * Show normal price, new price and savings

add_filter('woocommerce_get_price_html', 'sc_woo_product_price_savings_format', 10, 2);

function sc_woo_product_price_savings_format($price, $product) {

  if ($product->is_on_sale() && $product->is_type('simple')) {
    $price = sprintf( __('<div class="was-now-save"><div class="was"><strong>Was:</strong> %1$s</div><div class="now"><strong>Now:</strong> %2$s</div><div class="save"><strong>Save:</strong> %3$s</div></div>', 'woocommerce'), wc_price ($product->get_regular_price()), wc_price($product->get_sale_price()), wc_price($product->get_regular_price() - $product->get_sale_price()));      

  return $price;

   View Raw Code ID: 91084