Skip to content

Instantly share code, notes, and snippets.

@DanielSantoro
Created October 13, 2017 20:10
Show Gist options
  • Save DanielSantoro/0b67853453fb3fcb927d32cf012a47ec to your computer and use it in GitHub Desktop.
Save DanielSantoro/0b67853453fb3fcb927d32cf012a47ec to your computer and use it in GitHub Desktop.
Change Variation Price Range to "Starting Price: "
<?php
/*
* Change Variable Product Display Price to "From: ____" using minimum price
*/
function 171013_variable_price_format( $price, $product ) {
$prefix = sprintf('%s: ', __('Starting Price:', '171013'));
$min_price_regular = $product->get_variation_regular_price( 'min', true );
$min_price_sale = $product->get_variation_sale_price( 'min', true );
$max_price = $product->get_variation_price( 'max', true );
$min_price = $product->get_variation_price( 'min', true );
$price = ( $min_price_sale == $min_price_regular ) ?
wc_price( $min_price_regular ) :
'<del>' . wc_price( $min_price_regular ) . '</del>' . '<ins>' . wc_price( $min_price_sale ) . '</ins>';
return ( $min_price == $max_price ) ?
$price :
sprintf('%s%s', $prefix, $price);
}
add_filter( 'woocommerce_variable_sale_price_html', '171013_variable_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', '171013_variable_price_format', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment