Answer the question
In order to leave comments, you need to log in
Is it possible to sort variations ( get_available_variations() ) by price automatically?
I display in the product card (loop) a list of variations with a price:
if( $product->is_type('variable') ) {
echo '<ul class="item-material-list">';
foreach($product->get_available_variations() as $variation ){
echo '<li class="item-material-item">';
$attributes = array();
foreach( $variation['attributes'] as $key => $value ){
$taxonomy = str_replace('attribute_', '', $key );
$term_name = get_term_by( 'slug', $value, $taxonomy )->name;
}
echo '<div class="item-material-name">'. $term_name .'</div>';
$active_price = floatval($variation['display_price']);
$regular_price = floatval($variation['display_regular_price']);
if( $active_price != $regular_price ){
$sale_price = $active_price;
}
echo '<div class="item-material-price">'. $active_price .'₽</div></li>';
}
echo '</ul>';
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question