Skip to content

Instantly share code, notes, and snippets.

@RiodeJaneiroo
Created November 12, 2018 15:53
Show Gist options
  • Save RiodeJaneiroo/23c469251322f8d32f6471c50060fad4 to your computer and use it in GitHub Desktop.
Save RiodeJaneiroo/23c469251322f8d32f6471c50060fad4 to your computer and use it in GitHub Desktop.
[Woocommerce] Изменение формата цены, вместо диапазона вывести "От:" #woocommerce #wordpress
**
* Изменить формат цены - вместо диапазона вывести "От: "
*
* @param float $price Цена товара.
* @param object $product Товар.
* @return string
*/
function variable_price_format_filter( $price, $product ) {
$prefix = 'От: ';
$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 :
$prefix . $price;
}
add_filter( 'woocommerce_variable_sale_price_html', 'variable_price_format_filter', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'variable_price_format_filter', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment