Created
June 26, 2018 12:23
-
-
Save patrickposner/d842361c2a9191aa7512fd0c5ec9a97e to your computer and use it in GitHub Desktop.
Fix single product display prices for variation price range modified with role based prices
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
add_filter( 'woocommerce_variable_sale_price_html', 'rbp_new_variation_price_order', 10, 2 ); | |
add_filter( 'woocommerce_variable_price_html', 'rbp_new_variation_price_order', 10, 2 ); | |
function rbp_new_variation_price_order() { | |
$product = wc_get_product( get_the_id() ); | |
if ( $product->is_type( 'variable' ) ) { | |
$variations = array(); | |
foreach ( $product->get_available_variations() as $variation ) { | |
array_push( $variations, $variation['display_price'] ); | |
} | |
asort( $variations, SORT_NUMERIC ); | |
$variations_ordered = array_values( $variations ); | |
$price = wc_price( reset( $variations_ordered ) ) . ' - ' . wc_price( end( $variations_ordered ) ); | |
return $price; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment