Created
November 4, 2015 01:14
-
-
Save raisiqueira/6f72630e0286b92bfa5c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* https://gist.github.com/kloon/ | |
* Change Woocommerce grouped products. | |
* Muda de R$300-R$500 para | |
* de R$300 até R$500 | |
*/ | |
add_filter( 'woocommerce_grouped_price_html', 'wc_wc20_grouped_price_format', 10, 2 ); | |
function wc_wc20_grouped_price_format( $price, $product ) { | |
$tax_display_mode = get_option( 'woocommerce_tax_display_shop' ); | |
$child_prices = array(); | |
foreach ( $product->get_children() as $child_id ) { | |
$child_prices[] = get_post_meta( $child_id, '_price', true ); | |
} | |
$child_prices = array_unique( $child_prices ); | |
$get_price_method = 'get_price_' . $tax_display_mode . 'uding_tax'; | |
if ( ! empty( $child_prices ) ) { | |
$min_price = min( $child_prices ); | |
$max_price = max( $child_prices ); | |
} else { | |
$min_price = ''; | |
$max_price = ''; | |
} | |
if ( $min_price == $max_price ) { | |
$display_price = wc_price( $product->$get_price_method( 1, $min_price ) ); | |
} else { | |
$from = wc_price( $product->$get_price_method( 1, $min_price ) ); | |
$ate = wc_price( $product->$get_price_method( 1, $max_price ) ); | |
$display_price = sprintf( __( 'de %1$s', 'woocommerce' ), $from ).sprintf( __( ' até %1$s', 'woocommerce' ), $ate ); | |
} | |
return $display_price; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment