How to Display Discounted Price in Percentage & Number Both Format for WooCommerce Products

preview_player
Показать описание
In this woocommerce tutorial for beginners you will learn how to show discount price in percentage and number format with regular and sale price for woocommerce product in wordpress website using custom php snippet. So after adding code save price show in both way e.g. percentage & number for all product include variable and simple products pages and also show on woocoommerce archive / archives page like shop, category, tags etc.

** Find Custom Code in Top Pinned Comment Section.

** you can add css with your custom class.

display:flex;
}

* If above css work then good otherwise find your custom css class for price section then add display flex.

** Adding space between price then use this css class:

.saved-sale
{
margin-left:5px;
}

#discount #percentage #price #number #saleprice #discountedprices #discounted #product #products #shop #woocommerce #simple #variable #wordpress #wordpresstutorial #webtaskwithhassan #hassangilani
Рекомендации по теме
Комментарии
Автор

Use this code:

add_filter( 'woocommerce_get_price_html', 'change_displayed_sale_price_html_percentage_number', 10, 2 );
function $price, $product ) {
// Only on sale products on frontend and excluding min/max price on variable products
if( $product->is_on_sale() && ! is_admin() && !
// Get product prices
$regular_price = (float) // Regular price
$sale_price = (float) $product->get_price(); // Active price (the "Sale price" when on-sale)

// "Saving price" calculation and formatting
$saving_price = wc_price( $regular_price - $sale_price );

// "Saving Percentage" calculation and formatting
$precision = 1; // Max number of decimals
$saving_percentage = round( 100 - ( $sale_price / $regular_price * 100 ), 1 ) . '%';

// Append to the formated html price
$price .= sprintf( __('<p class="saved-sale">Save: %s <em>(%s)</em></p>', 'woocommerce' ), $saving_price, $saving_percentage );
}
return $price;
}

WebTaskWithHassan
Автор

How to show price according to country

SameerAhmad-nlfv