Skip to content

Instantly share code, notes, and snippets.

@kreamweb
Created February 2, 2018 08:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kreamweb/7f33d375e7a3e0a46c6322f6cf13834c to your computer and use it in GitHub Desktop.
Save kreamweb/7f33d375e7a3e0a46c6322f6cf13834c to your computer and use it in GitHub Desktop.
Change the variation price with FROM: ----
<?php
add_filter( 'woocommerce_get_price_html', 'ywsbs_woocommerce_get_variation_price_html', 99, 2 );
add_filter( 'woocommerce_get_variation_price_html', 'ywsbs_woocommerce_get_variation_price_html', 99, 2 );
function ywsbs_woocommerce_get_variation_price_html( $price, $product ){
if ( ! $product->is_type('variable') ){
return $price;
}
$prefix = sprintf('%s: ', __('From', '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', $prefix, $price);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment