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
variable.php
86 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Variable product add to cart |
| 4 | * |
| 5 | * This template can be overridden by copying it to yourtheme/woocommerce/single-product/add-to-cart/variable.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 6.1.0 |
| 16 | */ |
| 17 | |
| 18 | defined( 'ABSPATH' ) || exit; |
| 19 | |
| 20 | global $product; |
| 21 | |
| 22 | $attribute_keys = array_keys( $attributes ); |
| 23 | $variations_json = wp_json_encode( $available_variations ); |
| 24 | $variations_attr = function_exists( 'wc_esc_json' ) ? wc_esc_json( $variations_json ) : _wp_specialchars( $variations_json, ENT_QUOTES, 'UTF-8', true ); |
| 25 | |
| 26 | do_action( 'woocommerce_before_add_to_cart_form' ); ?> |
| 27 | |
| 28 | <form class="variations_form cart" action="<?php echo esc_url( apply_filters( 'woocommerce_add_to_cart_form_action', $product->get_permalink() ) ); ?>" method="post" enctype='multipart/form-data' data-product_id="<?php echo absint( $product->get_id() ); ?>" data-product_variations="<?php echo $variations_attr; // WPCS: XSS ok. ?>"> |
| 29 | <?php do_action( 'woocommerce_before_variations_form' ); ?> |
| 30 | |
| 31 | <?php if ( empty( $available_variations ) && false !== $available_variations ) : ?> |
| 32 | <p class="stock out-of-stock"><?php echo esc_html( apply_filters( 'woocommerce_out_of_stock_message', __( 'This product is currently out of stock and unavailable.', 'woocommerce' ) ) ); ?></p> |
| 33 | <?php else : ?> |
| 34 | <table class="variations" cellspacing="0" role="presentation"> |
| 35 | <tbody> |
| 36 | <?php foreach ( $attributes as $attribute_name => $options ) : ?> |
| 37 | <tr> |
| 38 | <th class="label"><label for="<?php echo esc_attr( sanitize_title( $attribute_name ) ); ?>"><?php echo wc_attribute_label( $attribute_name ); // WPCS: XSS ok. ?></label></th> |
| 39 | <td class="value"> |
| 40 | <?php |
| 41 | wc_dropdown_variation_attribute_options( |
| 42 | array( |
| 43 | 'options' => $options, |
| 44 | 'attribute' => $attribute_name, |
| 45 | 'product' => $product, |
| 46 | ) |
| 47 | ); |
| 48 | echo end( $attribute_keys ) === $attribute_name ? wp_kses_post( apply_filters( 'woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . esc_html__( 'Clear', 'woocommerce' ) . '</a>' ) ) : ''; |
| 49 | ?> |
| 50 | </td> |
| 51 | </tr> |
| 52 | <?php endforeach; ?> |
| 53 | </tbody> |
| 54 | </table> |
| 55 | <?php do_action( 'woocommerce_after_variations_table' ); ?> |
| 56 | |
| 57 | <div class="single_variation_wrap"> |
| 58 | <?php |
| 59 | /** |
| 60 | * Hook: woocommerce_before_single_variation. |
| 61 | */ |
| 62 | do_action( 'woocommerce_before_single_variation' ); |
| 63 | |
| 64 | /** |
| 65 | * Hook: woocommerce_single_variation. Used to output the cart button and placeholder for variation data. |
| 66 | * |
| 67 | * @since 2.4.0 |
| 68 | * @hooked woocommerce_single_variation - 10 Empty div for variation data. |
| 69 | * @hooked woocommerce_single_variation_add_to_cart_button - 20 Qty and cart button. |
| 70 | */ |
| 71 | do_action( 'woocommerce_single_variation' ); |
| 72 | |
| 73 | /** |
| 74 | * Hook: woocommerce_after_single_variation. |
| 75 | */ |
| 76 | do_action( 'woocommerce_after_single_variation' ); |
| 77 | ?> |
| 78 | </div> |
| 79 | <?php endif; ?> |
| 80 | |
| 81 | <?php do_action( 'woocommerce_after_variations_form' ); ?> |
| 82 | </form> |
| 83 | |
| 84 | <?php |
| 85 | do_action( 'woocommerce_after_add_to_cart_form' ); |
| 86 |