2011-12-09 20:16:34 +00:00
< ? php
/**
* Grouped Product Add to Cart
*/
2011-12-11 14:40:25 +00:00
global $woocommerce , $product ;
2011-12-19 18:42:21 +00:00
// Put grouped products into an array
$grouped_products = array ();
$all_products_are_downloadable = true ;
foreach ( $product -> get_children () as $child_id ) :
$child_product = $product -> get_child ( $child_id );
if ( ! $child_product -> is_downloadable () || ! $child_product -> is_virtual () ) $all_products_are_downloadable = false ;
$grouped_products [] = array (
'product' => $child_product ,
'availability' => $child_product -> get_availability ()
);
endforeach ;
2011-12-09 20:16:34 +00:00
?>
< ? php do_action ( 'woocommerce_before_add_to_cart_form' ); ?>
2011-12-11 14:40:25 +00:00
< form action = " <?php echo esc_url( $product->add_to_cart_url () ); ?> " class = " cart " method = " post " enctype = 'multipart/form-data' >
2011-12-09 20:16:34 +00:00
< table cellspacing = " 0 " class = " group_table " >
< tbody >
2011-12-19 18:42:21 +00:00
< ? php foreach ( $grouped_products as $child_product ) : ?>
2011-12-09 20:16:34 +00:00
< tr >
2011-12-19 18:42:21 +00:00
< td >
< ? php if ( $all_products_are_downloadable ) : ?>
2012-01-05 11:31:22 +00:00
< button type = " submit " name = " quantity[<?php echo $child_product['product'] ->id; ?>] " value = " 1 " class = " button alt " >< ? php _e ( 'Add to cart' , 'woocommerce' ); ?> </button>
2011-12-19 18:42:21 +00:00
< ? php else : ?>
< ? php woocommerce_quantity_input ( array ( 'input_name' => 'quantity[' . $child_product [ 'product' ] -> id . ']' , 'input_value' => '0' ) ); ?>
< ? php endif ; ?>
</ td >
< td >< label for = " product-<?php echo $child_product['product'] ->id; ?> " >< ? php
if ( $child_product [ 'product' ] -> is_visible ()) echo '<a href="' . get_permalink ( $child_product [ 'product' ] -> id ) . '">' ;
echo $child_product [ 'product' ] -> get_title ();
if ( $child_product [ 'product' ] -> is_visible ()) echo '</a>' ;
2011-12-09 20:16:34 +00:00
?> </label></td>
2011-12-19 18:42:21 +00:00
< td class = " price " >< ? php echo $child_product [ 'product' ] -> get_price_html (); ?>
< ? php echo apply_filters ( 'woocommerce_stock_html' , '<small class="stock ' . $child_product [ 'availability' ][ 'class' ] . '">' . $child_product [ 'availability' ][ 'availability' ] . '</small>' , $child_product [ 'availability' ][ 'availability' ] ); ?>
2011-12-09 20:16:34 +00:00
</ td >
</ tr >
< ? php endforeach ; ?>
</ tbody >
</ table >
2011-12-19 18:42:21 +00:00
< ? php if ( ! $all_products_are_downloadable ) : ?>
< ? php do_action ( 'woocommerce_before_add_to_cart_button' ); ?>
2012-02-21 13:40:05 +00:00
< button type = " submit " class = " button alt " >< ? php echo apply_filters ( 'single_add_to_cart_text' , __ ( 'Add to cart' , 'woocommerce' ), $product -> product_type ); ?> </button>
2011-12-19 18:42:21 +00:00
< ? php do_action ( 'woocommerce_after_add_to_cart_button' ); ?>
< ? php endif ; ?>
2011-12-09 20:16:34 +00:00
</ form >
< ? php do_action ( 'woocommerce_after_add_to_cart_form' ); ?>