woocommerce/templates/single-product/add-to-cart/grouped.php

83 lines
2.9 KiB
PHP
Raw Normal View History

2011-12-09 20:16:34 +00:00
<?php
/**
2012-08-14 18:05:45 +00:00
* Grouped product add to cart
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 1.6.4
2011-12-09 20:16:34 +00:00
*/
2012-08-14 18:05:45 +00:00
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
global $woocommerce, $product;
// Put grouped products into an array
$grouped_products = array();
2012-03-30 15:10:14 +00:00
$quantites_required = false;
2012-03-30 15:10:14 +00:00
foreach ( $product->get_children() as $child_id ) {
2012-08-14 18:05:45 +00:00
$child_product = $product->get_child( $child_id );
if ( ! $child_product->is_sold_individually() && ! $child_product->is_type('external') )
2012-03-30 15:10:14 +00:00
$quantites_required = true;
2012-08-14 18:05:45 +00:00
$grouped_products[] = array(
'product' => $child_product,
'availability' => $child_product->get_availability()
2012-08-14 18:05:45 +00:00
);
2012-03-30 15:10:14 +00:00
}
2011-12-09 20:16:34 +00:00
?>
<?php do_action('woocommerce_before_add_to_cart_form'); ?>
<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>
2012-03-30 15:10:14 +00:00
<?php foreach ( $grouped_products as $child_product ) : ?>
2011-12-09 20:16:34 +00:00
<tr>
<td>
<?php if ( $child_product['product']->is_type('external') ) : ?>
2012-08-14 18:05:45 +00:00
<a href="<?php echo esc_url( $child_product['product']->get_product_url() ); ?>" rel="nofollow" class="button alt"><?php echo apply_filters('single_add_to_cart_text', esc_html( $child_product['product']->get_button_text() ), 'external'); ?></a>
2012-08-14 18:05:45 +00:00
2012-03-30 15:10:14 +00:00
<?php elseif ( ! $quantites_required ) : ?>
2012-08-14 18:05:45 +00:00
2012-10-16 09:45:33 +00:00
<button type="submit" name="quantity[<?php echo $child_product['product']->id; ?>]" value="1" class="single_add_to_cart_button button alt"><?php _e( 'Add to cart', 'woocommerce' ); ?></button>
2012-08-14 18:05:45 +00:00
<?php else : ?>
2012-08-14 18:05:45 +00:00
<?php woocommerce_quantity_input( array( 'input_name' => 'quantity['.$child_product['product']->id.']', 'input_value' => '0' ) ); ?>
2012-08-14 18:05:45 +00:00
<?php endif; ?>
</td>
2012-08-14 18:05:45 +00:00
<td class="label"><label for="product-<?php echo $child_product['product']->id; ?>"><?php
2012-08-14 18:05:45 +00:00
if ($child_product['product']->is_visible())
2012-12-11 17:28:47 +00:00
echo '<a href="' . get_permalink( $child_product['product']->id ) . '">' . $child_product['product']->post->post_title . '</a>';
2012-03-30 15:10:14 +00:00
else
2012-12-11 17:28:47 +00:00
echo $child_product['product']->post->post_title;
2012-08-14 18:05:45 +00:00
2011-12-09 20:16:34 +00:00
?></label></td>
2012-08-14 18:05:45 +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>
2012-08-14 18:05:45 +00:00
2012-03-30 15:10:14 +00:00
<?php if ( $quantites_required ) : ?>
2012-08-14 18:05:45 +00:00
<?php do_action('woocommerce_before_add_to_cart_button'); ?>
2012-08-14 18:05:45 +00:00
2012-10-16 09:45:33 +00:00
<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>
2012-08-14 18:05:45 +00:00
<?php do_action('woocommerce_after_add_to_cart_button'); ?>
2012-08-14 18:05:45 +00:00
<?php endif; ?>
2011-12-09 20:16:34 +00:00
</form>
<?php do_action('woocommerce_after_add_to_cart_form'); ?>