Forked from aschroder/woocommerce_template_functions.php
Created
August 28, 2012 06:35
-
-
Save aqeelashraf/3495541 to your computer and use it in GitHub Desktop.
Hack Woocommerce to add product custom fields - updated
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
<form action="<?php echo esc_url( $_product->add_to_cart_url() ); ?>" class="variations_form cart" method="post"> | |
<table class="variations" cellspacing="0"> | |
<tbody> | |
<?php foreach ($attributes as $name => $options) : ?> | |
<tr> | |
<td><label for="<?php echo sanitize_title($name); ?>"><?php echo $woocommerce->attribute_label($name); ?></label></td> | |
// START HACK HERE | |
<?php if(is_array($options) && $options[0] == "CUSTOM_TEXT") : ?> | |
<td> <input type="text" id="<?php echo esc_attr( sanitize_title($name) ); ?>" name="attribute_<?php echo sanitize_title($name); ?>"/></td> | |
<?php else: ?> | |
<td><select id="<?php echo esc_attr( sanitize_title($name) ); ?>" name="attribute_<?php echo sanitize_title($name); ?>"> | |
<option value=""><?php echo __('Choose an option', 'woothemes') ?>…</option> | |
<?php if(is_array($options)) : ?> | |
<?php | |
// Get terms if this is a taxonomy - ordered | |
if (taxonomy_exists(sanitize_title($name))) : | |
$args = array('menu_order' => 'ASC'); | |
$terms = get_terms( sanitize_title($name), $args ); | |
foreach ($terms as $term) : | |
if (!in_array($term->slug, $options)) continue; | |
echo '<option value="'.$term->slug.'">'.$term->name.'</option>'; | |
endforeach; | |
else : | |
foreach ($options as $option) : | |
echo '<option value="'.$option.'">'.$option.'</option>'; | |
endforeach; | |
endif; | |
?> | |
<?php endif;?> | |
</td> | |
<?php endif;?> | |
// END HACK HERE | |
</tr> | |
<?php endforeach;?> | |
</tbody> | |
</table> | |
<div class="single_variation_wrap" style="display:none;"> | |
<div class="single_variation"></div> | |
<div class="variations_button"> | |
<input type="hidden" name="variation_id" value="" /> | |
<div class="quantity"><input name="quantity" value="1" size="4" title="Qty" class="input-text qty text" maxlength="12" /></div> | |
<button type="submit" class="button alt"><?php _e('Add to cart', 'woothemes'); ?></button> | |
</div> | |
</div> | |
<div><input type="hidden" name="product_id" value="<?php echo esc_attr( $post->ID ); ?>" /></div> | |
<?php do_action('woocommerce_add_to_cart_form'); ?> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment