AI Verified

Name

Show percent savings on sale

About

You work a lot with offer prices? Then show your visitors how much they have saved compared to the original price.

Language

PHP

Rating

Voted: 0 by 0 user(s)

Codevault

jbeer

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: Not Specified

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

18/05/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Show percent savings on sale

 
                    
1if ( !function_exists( 'evolution_custom_sales_price' ) ) :
2/**
3 * Show percent savings on sale - Only for WooCommerce version 3.0+
4 *
5 * @add filter to products
6 *
7 * @return filter
8 */
9function evolution_custom_sales_price( $price, $regular_price, $sale_price ) {
10 
11 $percentage = round( ( $regular_price - $sale_price ) / $regular_price * 100 ).'%';
12 
13 $percentage_txt = __(' Save ', 'evolution' ).$percentage;
14 
15 $price = '<del>' . ( is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price ) . '</del> <ins>' . ( is_numeric( $sale_price ) ? wc_price( $sale_price ) . $percentage_txt : $sale_price . ' ' . $percentage_txt ) . '</ins>';
16 return $price;
17 
18}
19add_filter( 'woocommerce_format_sale_price', 'evolution_custom_sales_price', 10, 3 );
20endif;

0

Featured Snippet

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

0

WooCommerce Add Product-Unique Content Below Loop Item Image

Added: 1 year ago

Last Updated: 1 year ago

Showing product-specific content below the image on a loop item is really easy. In other words, if you want to show content, unique to each individual product below the product featured image on the p...

WooCommerce

AI Verified

1

WooCommerce Show Sale Price Dates On Product Page

Added: 1 year ago

Last Updated: 1 day ago

This snippet allows you to show the date range a product is on sale if you had set a sale price in the editor.

WooCommerce

AI Verified

1

WooCommerce Add Custom Text Field To Product

Added: 1 year ago

Last Updated: 1 year ago

In this example, we show you how customer can add custom text to products which will show on the product page, cart, checkout, thank you page, and order editor.

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WooCommerce

AI Verified

3

Confirm Password Field in Woocommerce

Added: 1 year ago

Last Updated: 1 day ago

WooCommerce

AI Verified

3

Redirect customers to own thank-you page after order

Added: 1 year ago

Last Updated: 1 day ago

You may want to redirect your customers to a custom thank you page after they place an order. You can do that with the following WooCommerce snippet

WooCommerce

AI Verified

2

Bypass logout confirmation.

Added: 1 year ago

Last Updated: 1 month ago