Last active
March 21, 2017 20:04
-
-
Save marcosnakamine/3c9d0b67994b02fb65303a43c5da2805 to your computer and use it in GitHub Desktop.
WooCommerce - Basic form for variable product
This file contains hidden or 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
<?php $product = wc_get_product( get_the_ID() ) ?> | |
<form class="txt" method="post" action="<?php the_permalink() ?>?add=<?php get_the_ID() ?>"> | |
<span class="ref">Ref. <?php echo $product->get_sku() ?></span> | |
<div class="price"> | |
<p><?php echo woocommerce_price( $product->get_price_including_tax() ) ?></p> | |
<p> | |
</div> | |
<div class="attributes"> | |
<?php $attributes = $product->get_attributes() // GET ALL ATRIBUTES ?> | |
<?php foreach( $attributes as $key => $value ): ?> | |
<select name="attribute_pa_<?php echo $attribute_name ?>" id="attribute_pa_<?php echo $attribute_name ?>"> | |
<?php $attribute_name = wc_get_product_terms( get_the_ID(), $key ) // GET ATTRIBUTE NAME ?> | |
<?php $attribute_slug = wc_get_product_terms( get_the_ID(), $key, array( 'fields' => 'slugs' ) ) // GET ATTRIBUTE SLUG ?> | |
<?php for ( $i=0; $i<count( $attribute_name ); $i++ ): // array_slice BECAUSE ARRAY INDEX IS NOT SEQUENCIAL ?> | |
<option value="<?php $slug = array_slice( $attribute_slug, $i, 1 ); echo $slug[0]; ?>"><?php $name = array_slice( $attribute_name, $i, 1 ); echo $name[0]; ?></option> | |
<?php endfor ?> | |
</select> | |
<?php endforeach ?> | |
</div> | |
<input type="hidden" name="add-to-cart" value="<?php echo $product->id ?>"> | |
<input type="hidden" name="product_id" value="<?php echo $product->id ?>"> | |
<input type="hidden" name="quantity" value="1"> | |
<button class="bt-comprar">COMPRAR</button> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment