Actually both. I first added some codes to the function file but the addons wasn’t displaying. I then tried two plugins ie. Woo Variation table and Ni WooCommerce Product Variation.
However, below is the code I used to display the table. What am I doing wrong, please?
function woocommerce_variable_add_to_cart() {
global $product;
$variations = $product->get_available_variations();
foreach ($variations as $key => $value) {
?>
<form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>"method="post" enctype='multipart/form-data'>
<input type="hidden" name="variation_id" value="<?php echo $value['variation_id']?>" />
<input type="hidden" name="add-to-cart" value="<?php echo absint( $product->get_id() ); ?>" />
<input type="hidden" name="product_id" value="<?php echo absint( $product->get_id() ); ?>" />
<?php
if(!empty($value['attributes'])){
foreach ($value['attributes'] as $attr_key => $attr_value) {
?>
<input type="hidden" name="<?php echo $attr_key?>" value="<?php echo $attr_value?>">
<?php
}
}
?>
<table>
<tbody>
<tr>
<td>
<?php foreach ($value['attributes'] as $attrKey => $attr) :
$tax = str_replace('attribute_', '', $attrKey);
$term_obj = get_term_by('slug', $attr, $tax); ?>
<td style="width: 40%; float: left;"><b> <?php echo $term_obj->name; ?></b></td>
<?php endforeach; ?>
</td >
<td style="width: 30%; float: left;">
<?php echo $value['price_html'];?>
</td>
<td style="width: 30%;float: right;">
<button type="submit" class="single_add_to_cart_button button alt"><?php echo apply_filters('single_add_to_cart_text', __( 'Add to cart', 'woocommerce' ), $product->product_type); ?></button>
</td>
</tr>
</tbody>
</table>
</form>
<?php
}
}