WooCommerce Preisspanne: Von bis Preise in Ab Preise ändern

von Eric-Oliver Mächler | Feb. 15, 2018 | eCommerce, Technik | 40 Kommentare

Schlagwörter: functions.phpWooCommerce

Wenn man ein WooCommerce Shop besitzt und variable Produkte eingebaut hat, dann sieht man bei der Preisanzeige ein „Von bis“ Preisanzeige – also „2-10 CHF“.
Manchmal möchte man aber als Shopbetreiber nicht, dass man den Maximalen Preis angezeigt bekommt – denn das könnte Kunden abhalten zu kaufen. Aus diesem Grund möchte man vielleicht die Preisanzeige in der Übersichtseite so umformatiert haben „Ab 2 CHF“.

Video

Snippet

Mit diesem einfachen Snippet ist das Möglich – einfach dieses Snippet in die functions.php File reinkopieren und abspeichern und dann ist die Anzeige angepasst.

add_filter( 'woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2 );
function wc_wc20_variation_price_format( $price, $product ) {
// Main Price
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
$price = $prices[0] !== $prices[1] ? sprintf( __( ' ab %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
// Sale Price
$prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
sort( $prices );
$saleprice = $prices[0] !== $prices[1] ? sprintf( __( ' ab %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
 
if ( $price !== $saleprice ) {
$price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>';
}
return $price;
}

Da bei Divi 5 das Kommentar Modul einen Bug hat, habe ich diese Funktion deaktiviert. Es tut mir leid.

Wer gerne einen Kommentar hinterlassen möchte, der muss zur Zeit ausweichen auf Instagram oder LinkedIn. Jeder Beitrag wird dort auch veröffentlicht. Oder ihr schreibt mir eine eMail