I want to list my product variations in single product page in a table with their dimensions, everything is ok on dimension part but I cant get the variation name to be showed. Here is my code:
<?php
$variations = $product->get_available_variations();
foreach ( $variations as $variable_array ){
$variation = new WC_Product( $variable_array['variation_id'] );?>
<tr>
<td>
<b>here I need the variation title</b>
</td>
<?php
$magassag = $variation->height;
?>
<?php if ($magassag != 0) {
echo '<td class="cell_magas">' . $variation->height . ' cm' . '</td>'; }
else{
?>
<style type="text/css">#magassag-cim{display:none;}</style>
<?php } ?>
<?php
$atmero = $variation->width;
?>
<?php if ($atmero != 0) {
echo '<td class="cell_szell">' . $variation->width . ' cm' . '</td>'; }
else{
?>
<style type="text/css">#szellesseg-cim{display:none;}</style>
<?php } ?>
<?php
$szellesseg = $variation->length;
?>
<?php if ($szellesseg != 0) {
echo '<td class="cell_latime">' . $variation->length . ' cm' . '</td>'; }
else{
?>
<style type="text/css">#szellesseg-cim{display:none;}</style>
<?php } ?>
<td>
<?php echo $variation->price;?>
</td>
</tr>
You could use
$variation->get_formatted_name()
or$variation->get_title()
Also, I'm 95% sure you will want to use class methods instead of directly accessing the object properties will cause errors/warnings in WooCommerce 2.7. Plus it usually runs through a filter in case any plugins are targeting that value. (Ex: use
$variation->get_price()
instead of$variation->price
)