Last active
December 12, 2017 17:25
-
-
Save DanielSantoro/5a249e199e2bef2d0b5fe50523b7aafa to your computer and use it in GitHub Desktop.
Change Variable Price from Range to "From:"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //Do not insert this line | |
/** | |
* Change Variable Product price range to "From:" | |
*/ | |
function variable_price_display_change( $price, $product ) { | |
$prefix = sprintf('%s: ', __('From')); | |
$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', 'variable_price_display_change', 10, 2 ); | |
add_filter( 'woocommerce_variable_price_html', 'variable_price_display_change', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment