mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-29 11:32:21 +08:00
https://stackoverflow.com/questions/68646887/how-to-create-custom-label-and-show-lowest-variation-price-in-front-woocommerce
19 lines
748 B
Text
19 lines
748 B
Text
function reformat_pricing_labels( $price, $product ) {
|
|
|
|
$label = __( 'Starting', 'textdomain' );
|
|
|
|
$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 );
|
|
|
|
if ( $min_price_sale === $min_price_regular ) {
|
|
$price = wc_price( $min_price_regular );
|
|
}
|
|
|
|
return $min_price === $max_price ? $price : sprintf( '%s %s', $label, $price );
|
|
|
|
}
|
|
add_filter( 'woocommerce_variable_sale_price_html', 'reformat_pricing_labels', 10, 2 );
|
|
add_filter( 'woocommerce_variable_price_html', 'reformat_pricing_labels', 10, 2 );
|