Skip to content

Instantly share code, notes, and snippets.

@luizbills
Last active January 26, 2017 17:02
Show Gist options
  • Save luizbills/3c0f05673498367028912a6f6aae468f to your computer and use it in GitHub Desktop.
Save luizbills/3c0f05673498367028912a6f6aae468f to your computer and use it in GitHub Desktop.
custom_variable_price_html.php
<?php
/**
* @version 1.0.1
*/
add_filter( 'woocommerce_get_price_html', 'custom_variable_price_html', 10, 2 );
function custom_variable_price_html( $price, $product ) {
if ( ! $product->is_type( 'variable' ) || $product->get_price() === '') return $price;
$result = '';
$prices = $product->get_variation_prices( true );
if ( ! empty( $prices['price'] ) ) {
$min_price = current( $prices['price'] );
$max_price = end( $prices['price'] );
if ( ( ! $min_price ) || $min_price !== $max_price ) {
$result .= '<span class="from">' . __( 'A partir de', 'prefix' ) . ' </span>';
}
$result .= woocommerce_price( $min_price );
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment