simple.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Simple product add to cart
  4. *
  5. * This template can be overridden by copying it to yourtheme/woocommerce/single-product/add-to-cart/simple.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.0
  16. */
  17. defined( 'ABSPATH' ) || exit;
  18. global $product;
  19. if ( ! $product->is_purchasable() ) {
  20. return;
  21. }
  22. echo wc_get_stock_html( $product ); // WPCS: XSS ok.
  23. if ( $product->is_in_stock() ) : ?>
  24. <?php do_action( 'woocommerce_before_add_to_cart_form' ); ?>
  25. <form class="cart" action="<?php echo esc_url( apply_filters( 'woocommerce_add_to_cart_form_action', $product->get_permalink() ) ); ?>" method="post" enctype='multipart/form-data'>
  26. <?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
  27. <?php
  28. do_action( 'woocommerce_before_add_to_cart_quantity' );
  29. woocommerce_quantity_input( array(
  30. 'min_value' => apply_filters( 'woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product ),
  31. 'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product ),
  32. 'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( wp_unslash( $_POST['quantity'] ) ) : $product->get_min_purchase_quantity(), // WPCS: CSRF ok, input var ok.
  33. ) );
  34. do_action( 'woocommerce_after_add_to_cart_quantity' );
  35. ?>
  36. <button type="submit" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" class="single_add_to_cart_button button alt"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button>
  37. <?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
  38. </form>
  39. <?php do_action( 'woocommerce_after_add_to_cart_form' ); ?>
  40. <?php endif; ?>