Answer the question
In order to leave comments, you need to log in
Price format in a category from variable products, how to decide?
Hello!
Please tell me what is wrong.
Here the filter displays the minimum price of the variation in the product category.
add_filter('woocommerce_variable_price_html', 'custom_variation_price', 10, 2);
function custom_variation_price( $price, $product ) {
$price = '';
$price .= woocommerce_price($product->get_price());
return $price;
}
add_filter( 'woocommerce_variable_price_html', 'custom_min_max_variable_price_html', 10, 2 );
function custom_min_max_variable_price_html( $price, $product ) {
$prices = $product->get_variation_prices( true );
$min_price = current( $prices['price'] );
$max_price = end( $prices['price'] );
$min_keys = current(array_keys( $prices['price'] ));
$min_price_regular = $prices['regular_price'][$min_keys];
$min_price_html = wc_price( $min_price ) . $product->get_price_suffix();
if( $min_price_regular != $min_price ){ // When min price is on sale (Can be removed)
$min_price_regular_html = '<del>' . wc_price( $min_price_regular ) . $product->get_price_suffix() . '</del>';
$min_price_html = $min_price_regular_html .'<ins>' . $min_price_html . '</ins>';
}
$price = sprintf( __( '%1$s', 'woocommerce' ), $min_price_html );
return $price;
}
Answer the question
In order to leave comments, you need to log in
And so?
add_filter('woocommerce_variable_price_html', 'dco_woocommerce_variable_price_html');
function dco_woocommerce_variable_price_html($price) {
$array = explode(' – ', $price);
return '<span class="price-from">от</span> ' . $array[0];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question