external.php
3 years ago
grouped.php
3 years ago
simple.php
3 years ago
variable.php
4 years ago
variation-add-to-cart-button.php
3 years ago
variation.php
5 years ago
grouped.php
128 lines
| 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 | * @package WooCommerce\Templates |
| 15 | * @version 7.0.1 |
| 16 | */ |
| 17 | |
| 18 | defined( 'ABSPATH' ) || exit; |
| 19 | |
| 20 | global $product, $post; |
| 21 | |
| 22 | do_action( 'woocommerce_before_add_to_cart_form' ); ?> |
| 23 | |
| 24 | <form class="cart grouped_form" action="<?php echo esc_url( apply_filters( 'woocommerce_add_to_cart_form_action', $product->get_permalink() ) ); ?>" method="post" enctype='multipart/form-data'> |
| 25 | <table cellspacing="0" class="woocommerce-grouped-product-list group_table"> |
| 26 | <tbody> |
| 27 | <?php |
| 28 | $quantites_required = false; |
| 29 | $previous_post = $post; |
| 30 | $grouped_product_columns = apply_filters( |
| 31 | 'woocommerce_grouped_product_columns', |
| 32 | array( |
| 33 | 'quantity', |
| 34 | 'label', |
| 35 | 'price', |
| 36 | ), |
| 37 | $product |
| 38 | ); |
| 39 | $show_add_to_cart_button = false; |
| 40 | |
| 41 | do_action( 'woocommerce_grouped_product_list_before', $grouped_product_columns, $quantites_required, $product ); |
| 42 | |
| 43 | foreach ( $grouped_products as $grouped_product_child ) { |
| 44 | $post_object = get_post( $grouped_product_child->get_id() ); |
| 45 | $quantites_required = $quantites_required || ( $grouped_product_child->is_purchasable() && ! $grouped_product_child->has_options() ); |
| 46 | $post = $post_object; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 47 | setup_postdata( $post ); |
| 48 | |
| 49 | if ( $grouped_product_child->is_in_stock() ) { |
| 50 | $show_add_to_cart_button = true; |
| 51 | } |
| 52 | |
| 53 | echo '<tr id="product-' . esc_attr( $grouped_product_child->get_id() ) . '" class="woocommerce-grouped-product-list-item ' . esc_attr( implode( ' ', wc_get_product_class( '', $grouped_product_child ) ) ) . '">'; |
| 54 | |
| 55 | // Output columns for each product. |
| 56 | foreach ( $grouped_product_columns as $column_id ) { |
| 57 | do_action( 'woocommerce_grouped_product_list_before_' . $column_id, $grouped_product_child ); |
| 58 | |
| 59 | switch ( $column_id ) { |
| 60 | case 'quantity': |
| 61 | ob_start(); |
| 62 | |
| 63 | if ( ! $grouped_product_child->is_purchasable() || $grouped_product_child->has_options() || ! $grouped_product_child->is_in_stock() ) { |
| 64 | woocommerce_template_loop_add_to_cart(); |
| 65 | } elseif ( $grouped_product_child->is_sold_individually() ) { |
| 66 | echo '<input type="checkbox" name="' . esc_attr( 'quantity[' . $grouped_product_child->get_id() . ']' ) . '" value="1" class="wc-grouped-product-add-to-cart-checkbox" id="' . esc_attr( 'quantity-' . $grouped_product_child->get_id() ) . '" />'; |
| 67 | echo '<label for="' . esc_attr( 'quantity-' . $grouped_product_child->get_id() ) . '" class="screen-reader-text">' . esc_html__( 'Buy one of this item', 'woocommerce' ) . '</label>'; |
| 68 | } else { |
| 69 | do_action( 'woocommerce_before_add_to_cart_quantity' ); |
| 70 | |
| 71 | woocommerce_quantity_input( |
| 72 | array( |
| 73 | 'input_name' => 'quantity[' . $grouped_product_child->get_id() . ']', |
| 74 | 'input_value' => isset( $_POST['quantity'][ $grouped_product_child->get_id() ] ) ? wc_stock_amount( wc_clean( wp_unslash( $_POST['quantity'][ $grouped_product_child->get_id() ] ) ) ) : '', // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 75 | 'min_value' => apply_filters( 'woocommerce_quantity_input_min', 0, $grouped_product_child ), |
| 76 | 'max_value' => apply_filters( 'woocommerce_quantity_input_max', $grouped_product_child->get_max_purchase_quantity(), $grouped_product_child ), |
| 77 | 'placeholder' => '0', |
| 78 | ) |
| 79 | ); |
| 80 | |
| 81 | do_action( 'woocommerce_after_add_to_cart_quantity' ); |
| 82 | } |
| 83 | |
| 84 | $value = ob_get_clean(); |
| 85 | break; |
| 86 | case 'label': |
| 87 | $value = '<label for="product-' . esc_attr( $grouped_product_child->get_id() ) . '">'; |
| 88 | $value .= $grouped_product_child->is_visible() ? '<a href="' . esc_url( apply_filters( 'woocommerce_grouped_product_list_link', $grouped_product_child->get_permalink(), $grouped_product_child->get_id() ) ) . '">' . $grouped_product_child->get_name() . '</a>' : $grouped_product_child->get_name(); |
| 89 | $value .= '</label>'; |
| 90 | break; |
| 91 | case 'price': |
| 92 | $value = $grouped_product_child->get_price_html() . wc_get_stock_html( $grouped_product_child ); |
| 93 | break; |
| 94 | default: |
| 95 | $value = ''; |
| 96 | break; |
| 97 | } |
| 98 | |
| 99 | echo '<td class="woocommerce-grouped-product-list-item__' . esc_attr( $column_id ) . '">' . apply_filters( 'woocommerce_grouped_product_list_column_' . $column_id, $value, $grouped_product_child ) . '</td>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 100 | |
| 101 | do_action( 'woocommerce_grouped_product_list_after_' . $column_id, $grouped_product_child ); |
| 102 | } |
| 103 | |
| 104 | echo '</tr>'; |
| 105 | } |
| 106 | $post = $previous_post; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 107 | setup_postdata( $post ); |
| 108 | |
| 109 | do_action( 'woocommerce_grouped_product_list_after', $grouped_product_columns, $quantites_required, $product ); |
| 110 | ?> |
| 111 | </tbody> |
| 112 | </table> |
| 113 | |
| 114 | <input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" /> |
| 115 | |
| 116 | <?php if ( $quantites_required && $show_add_to_cart_button ) : ?> |
| 117 | |
| 118 | <?php do_action( 'woocommerce_before_add_to_cart_button' ); ?> |
| 119 | |
| 120 | <button type="submit" class="single_add_to_cart_button button alt<?php echo esc_attr( wc_wp_theme_get_element_class_name( 'button' ) ? ' ' . wc_wp_theme_get_element_class_name( 'button' ) : '' ); ?>"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button> |
| 121 | |
| 122 | <?php do_action( 'woocommerce_after_add_to_cart_button' ); ?> |
| 123 | |
| 124 | <?php endif; ?> |
| 125 | </form> |
| 126 | |
| 127 | <?php do_action( 'woocommerce_after_add_to_cart_form' ); ?> |
| 128 |