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

  1. <?php 
  2. /** 
  3. * Grouped product add to cart 
  4. * 
  5. * This template can be overridden by copying it to yourtheme/woocommerce/single-product/add-to-cart/grouped.php. 
  6. * 
  7. * HOWEVER, on occasion WooCommerce will need to update template files and you 
  8. * (the theme developer) will need to copy the new files to your theme to 
  9. * maintain compatibility. We try to do this as little as possible, but it does 
  10. * happen. When this occurs the version of the template file will be bumped and 
  11. * the readme will list any important changes. 
  12. * 
  13. * @see https://docs.woocommerce.com/document/template-structure/ 
  14. * @author WooThemes 
  15. * @package WooCommerce/Templates 
  16. * @version 3.0.6 
  17. */ 
  18. if ( ! defined( 'ABSPATH' ) ) { 
  19. exit; 
  20.  
  21. global $product, $post; 
  22.  
  23. do_action( 'woocommerce_before_add_to_cart_form' ); ?> 
  24.  
  25. <form class="cart" method="post" enctype='multipart/form-data'> 
  26. <table cellspacing="0" class="group_table"> 
  27. <tbody> 
  28. <?php 
  29. $quantites_required = false; 
  30. $previous_post = $post; 
  31.  
  32. foreach ( $grouped_products as $grouped_product ) { 
  33. $post_object = get_post( $grouped_product->get_id() ); 
  34. $quantites_required = $quantites_required || ( $grouped_product->is_purchasable() && ! $grouped_product->has_options() ); 
  35.  
  36. setup_postdata( $post =& $post_object ); 
  37. ?> 
  38. <tr id="product-<?php the_ID(); ?>" <?php post_class(); ?>> 
  39. <td> 
  40. <?php if ( ! $grouped_product->is_purchasable() || $grouped_product->has_options() ) : ?> 
  41. <?php woocommerce_template_loop_add_to_cart(); ?> 
  42.  
  43. <?php elseif ( $grouped_product->is_sold_individually() ) : ?> 
  44. <input type="checkbox" name="<?php echo esc_attr( 'quantity[' . $grouped_product->get_id() . ']' ); ?>" value="1" class="wc-grouped-product-add-to-cart-checkbox" /> 
  45.  
  46. <?php else : ?> 
  47. <?php 
  48. /** 
  49. * @since 3.0.0. 
  50. */ 
  51. do_action( 'woocommerce_before_add_to_cart_quantity' ); 
  52.  
  53. woocommerce_quantity_input( array( 
  54. 'input_name' => 'quantity[' . $grouped_product->get_id() . ']',  
  55. 'input_value' => isset( $_POST['quantity'][ $grouped_product->get_id() ] ) ? wc_stock_amount( $_POST['quantity'][ $grouped_product->get_id() ] ) : 0,  
  56. 'min_value' => apply_filters( 'woocommerce_quantity_input_min', 0, $grouped_product ),  
  57. 'max_value' => apply_filters( 'woocommerce_quantity_input_max', $grouped_product->get_max_purchase_quantity(), $grouped_product ),  
  58. ) ); 
  59.  
  60. /** 
  61. * @since 3.0.0. 
  62. */ 
  63. do_action( 'woocommerce_after_add_to_cart_quantity' ); 
  64. ?> 
  65. <?php endif; ?> 
  66. </td> 
  67. <td class="label"> 
  68. <label for="product-<?php echo $grouped_product->get_id(); ?>"> 
  69. <?php echo $grouped_product->is_visible() ? '<a href="' . esc_url( apply_filters( 'woocommerce_grouped_product_list_link', get_permalink(), $grouped_product->get_id() ) ) . '">' . get_the_title() . '</a>' : get_the_title(); ?> 
  70. </label> 
  71. </td> 
  72. <?php do_action( 'woocommerce_grouped_product_list_before_price', $grouped_product ); ?> 
  73. <td class="price"> 
  74. <?php 
  75. echo $grouped_product->get_price_html(); 
  76. echo wc_get_stock_html( $grouped_product ); 
  77. ?> 
  78. </td> 
  79. </tr> 
  80. <?php 
  81. $post = $previous_post; 
  82. ?> 
  83. </tbody> 
  84. </table> 
  85.  
  86. <input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" /> 
  87.  
  88. <?php if ( $quantites_required ) : ?> 
  89.  
  90. <?php do_action( 'woocommerce_before_add_to_cart_button' ); ?> 
  91.  
  92. <button type="submit" class="single_add_to_cart_button button alt"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button> 
  93.  
  94. <?php do_action( 'woocommerce_after_add_to_cart_button' ); ?> 
  95.  
  96. <?php endif; ?> 
  97. </form> 
  98.  
  99. <?php do_action( 'woocommerce_after_add_to_cart_form' ); ?> 
.