I’m trying to figure out where these functions are called within the WooCommerce products loop:
function woocommerce_simple_add_to_cart()
function woocommerce_variable_add_to_cart()
These functions load the ‘single-product/add-to-cart/simple.php’ template and the ‘single-product/add-to-cart/variable.php’ template, respectively.
I thought the content-product.php template might call these functions, but this template goes directly from:
do_action( 'woocommerce_after_shop_loop_item_title' );
to
do_action( 'woocommerce_after_shop_loop_item' );
The template for the shop loop item itself must be generated somewhere else in WooCommerce.
2
Answers
The simple and variable add_to_cart functions that load the templates:
'single-product/add-to-cart/simple.php'
and
'single-product/add-to-cart/variable.php'
are called by the 'woocommerce_template_single_add_to_cart' function with a variable in the function name, like this:
The 'woocommerce_template_single_add_to_cart' function is hooked to the 'woocommerce_single_product_summary' function which is called in the template file 'content-single-product.php' here:
For WooCommerce products loop, add to cart is called via
woocommerce_after_shop_loop_item
action hook oncontent-product.php
template file (lines 59 to 65), you have:So
woocommerce_template_loop_add_to_cart()
function is hooked in at priority 10, that is called via includes/wc-template-hooks.php file (line 96):Now we can take a look to
woocommerce_template_loop_add_to_cart()
function itself located on includes/wc-template-hooks.php file (from line 1339 to 1386):At the end of the function code, you can se that
loop/add-to-cart.php
template file is called…This should answer your question.