'Woocommerce customizing price range
I have a web store with some variable products. I don't want to display the price range (50.00€ - 100€) but i want to display something like this "from: 50€", but only in product loop. In single product page i want the price range like it is.
With this script in functions.php file i have done this but inside the single product page i have bellow the product some "Similar products" and "Recently viewed products' that they have the price range.
add_filter( 'woocommerce_get_price_html', 'change_variable_products_price_display', 10, 2 );
function change_variable_products_price_display( $price, $product ) {
// Only for variable products type
if( ! $product->is_type('variable') ) return $price;
$prices = $product->get_variation_prices( true );
if ( empty( $prices['price'] ) )
return apply_filters( 'woocommerce_variable_empty_price_html', '', $product );
if ( ( is_product() && isset($woocommerce_loop['name']) && ! empty($woocommerce_loop['name']) ) || ! is_product() ) {
$min_price = current( $prices['price'] );
$max_price = end( $prices['price'] );
$prefix_html = '<span style="color:#555;">from:</span>';
$prefix = $min_price !== $max_price ? $prefix_html : ''; // HERE the prefix
return apply_filters( 'woocommerce_variable_price_html', $prefix . wc_price( $min_price ) . $product->get_price_suffix(), $product );
} else {
return $price;
}
}
How i can change the price range to "from:" only in "Similar products" and "Recently viewed" inside the single product page?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
