Skip to content

Instantly share code, notes, and snippets.

@tmblog
Created September 17, 2017 14:52
Show Gist options
  • Save tmblog/2e99f7a2bbf85234b6cdade454731f94 to your computer and use it in GitHub Desktop.
Save tmblog/2e99f7a2bbf85234b6cdade454731f94 to your computer and use it in GitHub Desktop.
Lists woocommerce variable products as a list next to it instead of drop down.
if( $product->is_type( 'variable' ) ){
global $product, $post;
$variations = $product->get_available_variations();
?>
<table>
<tbody>
<?php
foreach ($variations as $key => $value) {
?>
<tr>
<td>
<b><?php echo implode('/', $value['attributes']);?></b>
</td>
<td>
<?php echo $value['price_html'];?>
</td>
<td>
<form action="" method="post" enctype='multipart/form-data'>
<input type="hidden" name="variation_id" value="<?php echo $value['variation_id']?>" />
<input type="hidden" name="product_id" value="<?php echo esc_attr( $post->ID ); ?>" />
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $post->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
}
}
?>
<button type="submit" class="single_add_to_cart_button ajax_add_to_cart button alt"><?php echo apply_filters('single_add_to_cart_text', __( 'Add to cart', 'woocommerce' ), $product->product_type); ?></button>
</form>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment