Skip to content

Instantly share code, notes, and snippets.

@gfcarvalho
Last active September 16, 2021 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gfcarvalho/933ed552d587411f1609dbb9b5d61ccf to your computer and use it in GitHub Desktop.
Save gfcarvalho/933ed552d587411f1609dbb9b5d61ccf to your computer and use it in GitHub Desktop.
Woocommerce - change variable price range to display the starting price ("A partir de")
<?php
/**
* Change variable price range to display the starting price (A partir de...
* https://wedevs.com/105501/disable-woocommerce-variable-product-price/
*/
function wc_varb_price_range( $wcv_price, $product ) {
$prefix = sprintf('%s: ', __('A partir de', 'wcvp_range'));
$wcv_reg_min_price = $product->get_variation_regular_price( 'min', true );
$wcv_min_sale_price = $product->get_variation_sale_price( 'min', true );
$wcv_max_price = $product->get_variation_price( 'max', true );
$wcv_min_price = $product->get_variation_price( 'min', true );
$wcv_price = ( $wcv_min_sale_price == $wcv_reg_min_price ) ?
wc_price( $wcv_reg_min_price ) :
'<del>' . wc_price( $wcv_reg_min_price ) . '</del>' . '<ins>' . wc_price( $wcv_min_sale_price ) . '</ins>';
return ( $wcv_min_price == $wcv_max_price ) ?
$wcv_price :
sprintf('%s%s', $prefix, $wcv_price);
}
add_filter( 'woocommerce_variable_sale_price_html', 'wc_varb_price_range', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'wc_varb_price_range', 10, 2 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment