-
AuthorPosts
-
November 1, 2019 at 10:44 pm #1153150
Hi,
Is it possible to show a discount percentage?When i put in a discount price it says 100 – with a strip true and behind the new price.
This is “fine” but u would like it if it shows somewhere that this is 25% is this possible?
https://thehorsestore.nl/product/la-valencio-jas-lang-marcella/thanks for your help
greatz myrnaNovember 3, 2019 at 12:33 am #1153408Hey thehorsestore,
This answer would likely be better found in the WooCommerce forums.
Best regards,
Jordan ShannonNovember 10, 2019 at 6:17 pm #1155361Thanks! i figured it out :-)
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));
}
}
// We keep the highest value
$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__( ‘-‘, ‘woocommerce’ ) . ‘ ‘ . $percentage . ‘</span>’;
}November 11, 2019 at 5:42 am #1155482Hi,
Great, I’m glad that you found a solution and thanks for sharing. Please let us know if you should need any further help on the topic or if we can close it.
Best regards,
RikardNovember 17, 2019 at 12:50 pm #1157612Thanks, you can close the topic
November 17, 2019 at 12:59 pm #1157617Hi,
Glad to hear we will close this now. Thank you for using Enfold.For your information, you can take a look at Enfold documentation here
For any other questions or issues, feel free to start new threads in the Enfold forum and we will gladly try to help you :)Best regards,
Mike -
AuthorPosts
- The topic ‘Discount percentage’ is closed to new replies.