woocommerce_template_loop_add_to_cart

Get the add to cart template for the loop.

Description

woocommerce_template_loop_add_to_cart(); 

Usage

  1. if ( !function_exists( 'woocommerce_template_loop_add_to_cart' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-add-to-cart-ajax-for-variable-products/woocommerce-ajax-add-to-cart-variable-products.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = woocommerce_template_loop_add_to_cart(); 
  7.  

Defined (1)

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

/woocommerce-ajax-add-to-cart-variable-products.php  
  1. function woocommerce_template_loop_add_to_cart() { 
  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->product_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. if ($product->product_type == "variable" ) { 
  18. woocommerce_variable_add_to_cart(); 
  19. else { 
  20. wc_get_template( 'loop/add-to-cart.php', $args );