woocommerce_template_loop_add_to_cart

Get the add to cart template for the loop.

Description

woocommerce_template_loop_add_to_cart( (array) $args = array() ); 

Parameters (1)

0. $args — Optional. (array) => array()
The args.

Usage

  1. if ( !function_exists( 'woocommerce_template_loop_add_to_cart' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-template-functions.php'; 
  3.  
  4. // The args. 
  5. $args = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = woocommerce_template_loop_add_to_cart($args); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-template-functions.php  
  1. function woocommerce_template_loop_add_to_cart( $args = array() ) { 
  2. global $product; 
  3.  
  4. if ( $product ) { 
  5. $defaults = array( 
  6. 'quantity' => 1,  
  7. 'class' => implode( ' ', array_filter( array( 
  8. 'button',  
  9. 'product_type_' . $product->get_type(),  
  10. $product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',  
  11. $product->supports( 'ajax_add_to_cart' ) ? 'ajax_add_to_cart' : '',  
  12. ) ) ),  
  13. ); 
  14.  
  15. $args = apply_filters( 'woocommerce_loop_add_to_cart_args', wp_parse_args( $args, $defaults ), $product ); 
  16.  
  17. wc_get_template( 'loop/add-to-cart.php', $args );