Search
 
SCRIPT & CODE EXAMPLE
 

PHP

functions file erased wordpress

add_filter( 'woocommerce_sale_flash', 'add_percentage_to_sale_badge', 20, 3 );
function add_percentage_to_sale_badge( $html, $post, $product ) {
    if( $product->is_type('variable')){
        $percentages = array();

        // Get all variation prices
        $prices = $product->get_variation_prices();

        // Loop through variation prices
        foreach( $prices['price'] as $key => $price ){
            // Only on sale variations
            if( $prices['regular_price'][$key] !== $price ){
                // Calculate and set in the array the percentage for each variation on sale
                $percentages[] = round(100 - ($prices['sale_price'][$key] / $prices['regular_price'][$key] * 100));
            }
        }
        $percentage = max($percentages) . '%';
    } else {
        $regular_price = (float) $product->get_regular_price();
        $sale_price    = (float) $product->get_sale_price();

        $percentage    = round(100 - ($sale_price / $regular_price * 100)) . '%';
    }
    return '<span class="onsale">' . esc_html__( 'SALE', 'woocommerce' ) . ' ' . $percentage . '</span>';
}
Comment

PREVIOUS NEXT
Code Example
Php :: can i do a relation between 2 coulnm in mongodb laravel 
Php :: php array to query string using array map 
Php :: 16 digit random password generator php code without function 
Php :: gd2 image resizing library in codeigniter 
Php :: laravel pagination bootstrap sorting column 
Php :: how to access laragon phpmyadmin in local network 
Php :: -inurl:(htm/html/php/pls/txt) intitle:index.of "last modified" (mp4/wma/aac/avi) 
Php :: symfony server:start not working 
Php :: How to make a custom helper function, available in every controller for Laravel 
Php :: escape class wordpress 
Php :: remove public from laravel 8 url 
Php :: jupiter/framework/admin/generators/option-generator.php on line 80 
Php :: PHP readfile() Function 
Php :: dispaly image on front end of custom taxonomy 
Php :: Lity in Wordpress 
Php :: laravel notion require 
Php :: php get list of months by year 
Php :: Primary Termlaravel recursive relationships 
Php :: PHP ord — Convert the first byte of a string to a value between 0 and 255 
Php :: oneliner if php 
Php :: how to rrestart brew php 
Php :: show all errors in php 
Php :: waht is middleware in laravel 
Php :: php parameters 
Php :: modifier un formulaire php 
Php :: use scope in statamic template 
Php :: old codestar gallery 
Php :: kill phpstorm process ubuntu 
Php :: Stripe Test - Laravel 
Php :: laravel timestamp not updating 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =