When you’re a WooCommerce store owner and you want to create some sale products, it’s all too easy to forget to update the “saving” amount on those products. You might find this a bit annoying because your customers will see the wrong saving amount. In this video you’ll see how to fix this problem with a simple WooCommerce plugin.
In todays tutorial we are going to learn how to add the feature in your ecommerce website, all for free.
Plugin used: Code Snippet
Copy and paste the code.
/**
* Author: Thiarara
* Version: 1.1
* licence: Free GPL
* Topic: WooCommerce Display Fixed Saving Amount On Sale Products
* Email support: contact@thiarara.co.ke
* Snippet Name: WooCommerce Display Fixed Saving Amount On Sale Products
* Snippet Author: Thiarara.co.ke
*/
// Simple Products
add_filter( 'woocommerce_get_price_html', 'woo_display_fixed_amount_savings_on_sale_simple_products', 10, 2 );
function woo_display_fixed_amount_savings_on_sale_simple_products( $price, $product ) {
if ( $product->is_on_sale() && $product->is_type( 'simple' ) ) {
$regular_price = $product->get_regular_price();
$sale_price = $product->get_sale_price();
$savings = $regular_price - $sale_price;
$price .= '<br><small>You save ' . wc_price($savings) . '!</small>';
}
return $price;
}
// Variations (appears once variations have been selected)
add_filter( 'woocommerce_available_variation', 'woo_display_fixed_amount_savings_on_sale_variable_products', 10, 3 );
function woo_display_fixed_amount_savings_on_sale_variable_products( $data, $product, $variation ) {
if( $variation->is_on_sale() ) {
$savings_amount = $data['display_regular_price'] - $data['display_price'];
$data['price_html'] .= 'You save' . wc_price($savings_amount);
}
return $data;
}
You may also like these post: How to make a WordPress news, magazine, blog website with Elementor; Colormag Theme.
[…] you may also like to read: Hot to add WooCommerce Display Fixed Saving Amount On Sale Products […]