From 8b557ab80e15a6c06f7db2e96a74e86798461d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20G=C3=A4chter?= <lukas.gaechter@mind.ch> Date: Mon, 9 Sep 2024 17:41:46 +0200 Subject: [PATCH] feat!: Remove `woocommerce_shop_loop` hook call in `Product::setup()` to reduce side effects (#48) --- .github/workflows/release.yml | 1 + defaults/archive-product.twig | 7 ++++++- lib/Product.php | 10 ---------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 95a917a..48769b2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,6 +4,7 @@ on: push: branches: - 1.x + - 2.x permissions: contents: write diff --git a/defaults/archive-product.twig b/defaults/archive-product.twig index 3cdb59a..19419f4 100644 --- a/defaults/archive-product.twig +++ b/defaults/archive-product.twig @@ -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 @@ -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 %} diff --git a/lib/Product.php b/lib/Product.php index 023da56..85c7084 100644 --- a/lib/Product.php +++ b/lib/Product.php @@ -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. *