Created
August 21, 2019 02:04
-
-
Save dospuntocero/f4d14ea6b72f4762e9afebc82b369ffb to your computer and use it in GitHub Desktop.
using a list of variations instead of a combobox on product pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function woocommerce_variable_add_to_cart() { | |
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="<?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="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 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