A kis kód használatával a Woocommerce terméklistában található akciós termékeknél megjelenik a kedvezmény mértéke %-ban kifejezve.
Mint általában, ezt a kódot is a Woocommerce functions.php fájlban kell elhelyezni.
A kód tesztelve Woocommerce 3.6.2 verzióig. Vélhetően ezen verziót túlhaladva is működik, de nincs rá semmiféle garancia.
[ihc-hide-content ihc_mb_type=”show” ihc_mb_who=”1″ ihc_mb_template=”1″ ]Ha elakadtál vagy bármi kérdésed van, keress e-mail címünkön!
/**
* Akcio-szazalek-termeklistaban-snippet.
* Tesztelve: Woocommerce 3.6.2
*/
function custom_product_sale_flash( $output, $post, $product ) {
global $product;
if($product->is_on_sale()) {
if($product->is_type( 'variable' ) )
{
$regular_price = $product->get_variation_regular_price();
$sale_price = $product->get_variation_price();
} else {
$regular_price = $product->get_regular_price();
$sale_price = $product->get_sale_price();
}
$percent_off = (($regular_price - $sale_price) / $regular_price) * 100;
return '<span class="onsale">' . round($percent_off) . '% AKCIÓ </span>';
}
}
add_filter( 'woocommerce_sale_flash', 'custom_product_sale_flash', 11, 3 );
[/ihc-hide-content]