variable.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 3.4.1
  16. */
  17. defined( 'ABSPATH' ) || exit;
  18. global $product;
  19. $attribute_keys = array_keys( $attributes );
  20. do_action( 'woocommerce_before_add_to_cart_form' ); ?>
  21. <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 htmlspecialchars( wp_json_encode( $available_variations ) ); // WPCS: XSS ok. ?>">
  22. <?php do_action( 'woocommerce_before_variations_form' ); ?>
  23. <?php if ( empty( $available_variations ) && false !== $available_variations ) : ?>
  24. <p class="stock out-of-stock"><?php esc_html_e( 'This product is currently out of stock and unavailable.', 'woocommerce' ); ?></p>
  25. <?php else : ?>
  26. <table class="variations" cellspacing="0">
  27. <tbody>
  28. <?php foreach ( $attributes as $attribute_name => $options ) : ?>
  29. <tr>
  30. <td class="label"><label for="<?php echo esc_attr( sanitize_title( $attribute_name ) ); ?>"><?php echo wc_attribute_label( $attribute_name ); // WPCS: XSS ok. ?></label></td>
  31. <td class="value">
  32. <?php
  33. wc_dropdown_variation_attribute_options( array(
  34. 'options' => $options,
  35. 'attribute' => $attribute_name,
  36. 'product' => $product,
  37. ) );
  38. 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>' ) ) : '';
  39. ?>
  40. </td>
  41. </tr>
  42. <?php endforeach; ?>
  43. </tbody>
  44. </table>
  45. <div class="single_variation_wrap">
  46. <?php
  47. /**
  48. * Hook: woocommerce_before_single_variation.
  49. */
  50. do_action( 'woocommerce_before_single_variation' );
  51. /**
  52. * Hook: woocommerce_single_variation. Used to output the cart button and placeholder for variation data.
  53. *
  54. * @since 2.4.0
  55. * @hooked woocommerce_single_variation - 10 Empty div for variation data.
  56. * @hooked woocommerce_single_variation_add_to_cart_button - 20 Qty and cart button.
  57. */
  58. do_action( 'woocommerce_single_variation' );
  59. /**
  60. * Hook: woocommerce_after_single_variation.
  61. */
  62. do_action( 'woocommerce_after_single_variation' );
  63. ?>
  64. </div>
  65. <?php endif; ?>
  66. <?php do_action( 'woocommerce_after_variations_form' ); ?>
  67. </form>
  68. <?php
  69. do_action( 'woocommerce_after_add_to_cart_form' );