The following code from github will add “- [max price]” to all variable products displayed in product archives.
I am wondering how I could also remove the “From” text inside the same filter.
add_filter('woocommerce_variable_price_html', 'custom_variation_price', 10, 2);
function custom_variation_price( $price, $product ) {
$price = '';
if ( !$product->min_variation_price || $product->min_variation_price !== $product->max_variation_price ) $price .= '<span class="from">' . _x('From', 'min_price', 'woocommerce') . ' </span>';
$price .= woocommerce_price($product->get_price());
if ( $product->max_variation_price && $product->max_variation_price !== $product->min_variation_price ) {
$price .= '<span class="to"> ' . _x('-', 'max_price', 'woocommerce') . ' </span>';
$price .= woocommerce_price($product->max_variation_price);
}
return $price;
}
I noticed this question answers how to remove the From text using the same filter parameters, but I haven’t been able to figure out how this works.
Go with commenting out this line:
and this won’t be added to the price output.
Well, it turns out I have done it but without really exactly how everything works.
I just change this line:
to:
Does anyone know exactly how the _x() function works? I did see their documentation but its not really descriptive.
Use this code to remove “FROM” text from the variable products: