woocommerce php shop change price variatio nto price from

Solutions on MaxInterview for woocommerce php shop change price variatio nto price from by the best coders in the world

showing results for - "woocommerce php shop change price variatio nto price from"
Marceau
23 Feb 2016
1/**
2 * Change price format from range to "From:"
3 *
4 * @param float $price
5 * @param obj $product
6 * @return str
7 */
8function iconic_variable_price_format( $price, $product ) {
9
10    $prefix = sprintf('%s: ', __('From', 'iconic'));
11
12    $min_price_regular = $product->get_variation_regular_price( 'min', true );
13    $min_price_sale    = $product->get_variation_sale_price( 'min', true );
14    $max_price = $product->get_variation_price( 'max', true );
15    $min_price = $product->get_variation_price( 'min', true );
16
17    $price = ( $min_price_sale == $min_price_regular ) ?
18        wc_price( $min_price_regular ) :
19        '<del>' . wc_price( $min_price_regular ) . '</del>' . '<ins>' . wc_price( $min_price_sale ) . '</ins>';
20
21    return ( $min_price == $max_price ) ?
22        $price :
23        sprintf('%s%s', $prefix, $price);
24
25}
26
27add_filter( 'woocommerce_variable_sale_price_html', 'iconic_variable_price_format', 10, 2 );
28add_filter( 'woocommerce_variable_price_html', 'iconic_variable_price_format', 10, 2 );