php - WooCommerce add quantity button to shop -


i know how can add simple quantity button woocommerce shop products.

image

here how modified loop/add-to-cart.php achieve this:

<?php     /**      * loop add cart      *      * @author      woothemes      * @package     woocommerce/templates      * @version     1.6.4      */      if ( ! defined( 'abspath' ) ) exit; // exit if accessed directly      global $product;     ?>      <?php if ( ! $product->is_in_stock() ) : ?>          <a href="<?php echo apply_filters( 'out_of_stock_add_to_cart_url', get_permalink( $product->id ) ); ?>" class="button"><?php echo apply_filters( 'out_of_stock_add_to_cart_text', __( 'read more', 'woocommerce' ) ); ?></a>      <?php else : ?>          <?php             $link = array(                 'url'   => '',                 'label' => '',                 'class' => ''             );              $handler = apply_filters( 'woocommerce_add_to_cart_handler', $product->product_type, $product );              switch ( $handler ) {                 case "variable" :                     $link['url']    = apply_filters( 'variable_add_to_cart_url', get_permalink( $product->id ) );                     $link['label']  = apply_filters( 'variable_add_to_cart_text', __( 'select options', 'woocommerce' ) );                 break;                 case "grouped" :                     $link['url']    = apply_filters( 'grouped_add_to_cart_url', get_permalink( $product->id ) );                     $link['label']  = apply_filters( 'grouped_add_to_cart_text', __( 'view options', 'woocommerce' ) );                 break;                 case "external" :                     $link['url']    = apply_filters( 'external_add_to_cart_url', get_permalink( $product->id ) );                     $link['label']  = apply_filters( 'external_add_to_cart_text', __( 'read more', 'woocommerce' ) );                 break;                 default :                     if ( $product->is_purchasable() ) {                         $link['url']    = apply_filters( 'add_to_cart_url', esc_url( $product->add_to_cart_url() ) );                         $link['label']  = apply_filters( 'add_to_cart_text', __( 'add cart', 'woocommerce' ) );                         $link['class']  = apply_filters( 'add_to_cart_class', 'add_to_cart_button' );                     } else {                         $link['url']    = apply_filters( 'not_purchasable_url', get_permalink( $product->id ) );                         $link['label']  = apply_filters( 'not_purchasable_text', __( 'read more', 'woocommerce' ) );                     }                 break;             }             if ( $product->product_type == 'simple' ) {                  ?>                 <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" class="cart" method="post" enctype='multipart/form-data'>                      <?php woocommerce_quantity_input(); ?>                      <button type="submit" class="button alt"><?php echo $label; ?></button>                  </form>                 <?php              } else {                 echo apply_filters( 'woocommerce_loop_add_to_cart_link', sprintf('<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="%s button product_type_%s">%s</a>', esc_url( $link['url'] ), esc_attr( $product->id ), esc_attr( $product->get_sku() ), esc_attr( $link['class'] ), esc_attr( $product->product_type ), esc_html( $link['label'] ) ), $product, $link );             }         ?>      <?php endif; ?> 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -