Skip to content

Instantly share code, notes, and snippets.

@iconicwp
Created January 23, 2018 13:47
Show Gist options
  • Save iconicwp/48b0df68fa252f5cc911ff4770c7ba28 to your computer and use it in GitHub Desktop.
Save iconicwp/48b0df68fa252f5cc911ff4770c7ba28 to your computer and use it in GitHub Desktop.
<?php
/**
* Change price format from range to "From:"
*
* @param float $price
* @param object $product
*
* @return string
*/
function iconic_variable_price_format( $price, $product ) {
$suffix = sprintf( '%s ', __( '+', 'iconic' ) );
$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', $price, $suffix );
}
add_filter( 'woocommerce_variable_sale_price_html', 'iconic_variable_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'iconic_variable_price_format', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment