Skip to content

Commit

Permalink
feat!: Remove woocommerce_shop_loop hook call in Product::setup()
Browse files Browse the repository at this point in the history
… to reduce side effects (#48)
  • Loading branch information
gchtr authored Sep 9, 2024
1 parent abd9022 commit 8b557ab
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- 1.x
- 2.x

permissions:
contents: write
Expand Down
7 changes: 6 additions & 1 deletion defaults/archive-product.twig
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

{% if fn('woocommerce_product_loop') %}
{#
# woocommerce_before_shop_loop hook.
# Hook: woocommerce_before_shop_loop.
#
# @hooked woocommerce_output_all_notices - 10
# @hooked woocommerce_result_count - 20
Expand All @@ -50,6 +50,11 @@
# calling `have_posts()`, we check if there are posts we can display.
#}
{% if fn('have_posts') %}
{##
# Hook: woocommerce_shop_loop.
#}
{% do action('woocommerce_shop_loop') %}

{{ fn('wc_get_template_part', 'content', 'product' ) }}
{% endif %}
{% endfor %}
Expand Down
10 changes: 0 additions & 10 deletions lib/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,6 @@ public static function build( WP_Post $wp_post): static {
return $post;
}

public function setup() {
parent::setup();

if ( ! is_singular( 'product' ) && did_action( 'woocommerce_before_shop_loop' ) > 0 ) {
do_action( 'woocommerce_shop_loop' );
}

return $this;
}

/**
* Get the first assigned product category.
*
Expand Down

0 comments on commit 8b557ab

Please sign in to comment.