For some reason when the price of the attributes is the same, it does not show the price in the table.
Can anyone assist me to spot what the issue might be?
if($product->is_type('variable')){
echo '<tr><td class="desc">Serving Size</td><td class="desc">Price</td></tr>';
foreach($product->get_available_variations() as $variation ){
// Attributes
$attributes = array();
foreach( $variation['attributes'] as $key => $value ){
$taxonomy = str_replace('attribute_', '', $key );
// $taxonomy_label = get_taxonomy( $taxonomy )->labels->singular_name;
$term_name = get_term_by( 'slug', $value, $taxonomy )->name;
$attributes[] = $taxonomy_label.''.$term_name;
}
echo '<tr><td>'.implode( ' | ', $attributes ).'</td>';
// Prices
$active_price = floatval($variation['display_price']); // Active price
$regular_price = floatval($variation['display_regular_price']); // Regular Price
if( $active_price != $regular_price ){
$sale_price = $active_price; // Sale Price
}
echo '<td>'.$variation['price_html'].'</td></tr>';
}
}
else {
echo '<tr><td class="desc">Price</td></tr>
<tr><td>'.$product->get_price_html().'</td></tr>';
}
My Answer:
>is_type('variable')) {
$variations = $product->get_available_variations();
$attributes = $product->get_attributes();
echo '
' . wc_attribute_label($attribute) . ' | ';Price | ';
---|---|
' . $value . ' | ';' . $variation['display_price'] . ' | ';
}
Rate this post
4 of 5 based on 3781 votesComments