How can I change woocommerce_sale_flash from Text to Discount Percentage

Alex

I would like to know what would be the code to change woocommerce_sale_flash from the default text which is "Sale!" to the Discount Percentage you actually are saving.

Just now I have this piece of code which changes the text of the sale flash icon:

add_filter('woocommerce_sale_flash', 'my_custom_sale_flash');
function my_custom_sale_flash($text, $post, $_product) {
return '<span class="onsale"> Discount!</span>';  
}

Instead of displaying the same text each time, it should display the actual discount (for example: 25% off) of the product.

Rohil_PHPBeginner

Try out this :

add_filter('woocommerce_sale_flash', 'my_custom_sale_flash');
function my_custom_sale_flash($text) {
    global $product;
    $percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );
    return '<span class="onsale">'.$percentage.'%</span>';  
}       

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I calculate cumulative percentage change from beginning period

From Dev

How can I change Text of Textview from other funcion?

From Dev

How can I change the passing percentage for code coverage?

From Dev

How do I change button text from "Choose an option" in Woocommerce?

From Dev

How can I keep this random code to keep the same odds but change from 100 items to 125? It still needs to be the same percentage as the 100

From Dev

How can I keep percentage-based elements from overlapping?

From Dev

How can I extract error percentage from a CrossTable into a variable?

From Dev

how do I write a script to change the discount in the Order Details table

From Dev

How to solve floating 0.01 value on percentage discount

From Dev

How can I change an urwid.Edit's text from the 'change' signal handler?

From Dev

How can I make the button text change, from text to an empty name with a delay?

From Dev

How can I change the color of label with * in text

From Dev

How can I change the text of a UIBarButtonItem in Swift

From Dev

How can I change the text with a button?

From Dev

How can I change the color of label with * in text

From Dev

How can I change the position of the text in a plot

From Dev

How can I change the color of text in Word

From Dev

How can I change the text position of connector?

From Dev

How can I change the text of a input box?

From Dev

How can I calculate a cascade sales discount scenario using TSQL?

From Dev

How can I put PayPal discount codes on my checkout

From Dev

How to change encoding from plain text to Unicode so that I can read special characters from a HTML?

From Dev

How can I change the text from a TextBlock in a SplitView.Pane from a page loaded into a Frame?

From Dev

Edge Animate - How can i access and change a text from a button in different symbols?

From Dev

How can I change the datatype of a column from integer to text in SQL Server?

From Dev

How can I change the text in a WPF menu item from the .cs file?

From Dev

How do I can change contents of some div sections while clicking text from another div

From Dev

How can I change a label dynamically on a page, based on input from a text box?

From Dev

How can I change Atom settings from the command line or a text editor?

Related Related

  1. 1

    How can I calculate cumulative percentage change from beginning period

  2. 2

    How can I change Text of Textview from other funcion?

  3. 3

    How can I change the passing percentage for code coverage?

  4. 4

    How do I change button text from "Choose an option" in Woocommerce?

  5. 5

    How can I keep this random code to keep the same odds but change from 100 items to 125? It still needs to be the same percentage as the 100

  6. 6

    How can I keep percentage-based elements from overlapping?

  7. 7

    How can I extract error percentage from a CrossTable into a variable?

  8. 8

    how do I write a script to change the discount in the Order Details table

  9. 9

    How to solve floating 0.01 value on percentage discount

  10. 10

    How can I change an urwid.Edit's text from the 'change' signal handler?

  11. 11

    How can I make the button text change, from text to an empty name with a delay?

  12. 12

    How can I change the color of label with * in text

  13. 13

    How can I change the text of a UIBarButtonItem in Swift

  14. 14

    How can I change the text with a button?

  15. 15

    How can I change the color of label with * in text

  16. 16

    How can I change the position of the text in a plot

  17. 17

    How can I change the color of text in Word

  18. 18

    How can I change the text position of connector?

  19. 19

    How can I change the text of a input box?

  20. 20

    How can I calculate a cascade sales discount scenario using TSQL?

  21. 21

    How can I put PayPal discount codes on my checkout

  22. 22

    How to change encoding from plain text to Unicode so that I can read special characters from a HTML?

  23. 23

    How can I change the text from a TextBlock in a SplitView.Pane from a page loaded into a Frame?

  24. 24

    Edge Animate - How can i access and change a text from a button in different symbols?

  25. 25

    How can I change the datatype of a column from integer to text in SQL Server?

  26. 26

    How can I change the text in a WPF menu item from the .cs file?

  27. 27

    How do I can change contents of some div sections while clicking text from another div

  28. 28

    How can I change a label dynamically on a page, based on input from a text box?

  29. 29

    How can I change Atom settings from the command line or a text editor?

HotTag

Archive