-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
woocommerce_shop_loop getting fired twice #42
Comments
The default WooCommerce template archive-product.php where the hook if ( wc_get_loop_prop( 'total' ) ) {
while ( have_posts() ) {
the_post();
/**
* Hook: woocommerce_shop_loop.
*/
do_action( 'woocommerce_shop_loop' );
wc_get_template_part( 'content', 'product' );
}
} In the Twig equivalent in https://github.com/mindkomm/timber-integration-woocommerce/blob/1.x/defaults/archive-product.twig, that part looks like this: {% if fn('wc_get_loop_prop', 'total') %}
{% for post in posts %}
{##
# Depending on your WooCommerce display settings, the
# `woocommerce_product_subcategories` function might reset the $wp_query global. By
# calling `have_posts()`, we check if there are posts we can display.
#}
{% if fn('have_posts') %}
{{ fn('wc_get_template_part', 'content', 'product' ) }}
{% endif %}
{% endfor %}
{% endif %} As you can see, there’s no But as I’ve come to realize over the years, stuff like this can lead to problems like yours and doing things that I thought are very clever are sometimes not 😆. I’m trying to better understand this before I take any action. So to confirm why this happens to you, could you answer the following questions?
|
Thanks @gchtr. So we're not including the archive-product.twig in our theme. All we are overriding it the content-product so just have content-product.twig in our theme, in order for us to load the product cards in templates outside of WooCommerce pages. Your explanation makes sense in this scenario, as we're presumably using the default archive-product.php which has the woocommerce_shop_loop action in, plus then your 'setup' method is then firing it again. Perhaps that 'setup' method can check to see if that action has already run or if the archive-product.twig is being loaded in the theme? |
In Product.php on line 71, the integration is firing the woocommerce_shop_loop action again meaning that any functions hooked to that are being duplicated. Is there a reason why that is there?
We have a component that is loaded in on that action and therefor it's currently being loaded twice. When we comment out line 71, it's only loaded once as expected.
Thanks
The text was updated successfully, but these errors were encountered: