Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Review the execution sequence of the single product page hooks #10381

Closed
jimjasson opened this issue Jul 27, 2023 · 2 comments · Fixed by #11953
Closed

Review the execution sequence of the single product page hooks #10381

jimjasson opened this issue Jul 27, 2023 · 2 comments · Fixed by #11953
Assignees
Labels
type: bug The issue/PR concerns a confirmed bug.

Comments

@jimjasson
Copy link

Describe the bug

When the block-based single product template is used, and I install the following snippet that prints the single product page hooks:

add_action( 'woocommerce_before_single_product', 'before_single_product' );

function before_single_product() {
	error_log( "before_single_product" );
}

add_action( 'woocommerce_before_add_to_cart_button', 'before_add_to_cart_button' );

function before_add_to_cart_button() {
	error_log( "before_add_to_cart_button" );
}

add_action( 'woocommerce_single_product_summary', 'single_product_summary' );

function single_product_summary() {
	error_log( "single_product_summary" );
}

add_action( 'woocommerce_product_meta_start', 'meta_start' );

function meta_start() {
	error_log( "meta_start" );
}

add_action( 'woocommerce_after_single_product_summary', 'after_single_product_summary' );

function after_single_product_summary() {
	error_log( "after_single_product_summary" );
}

add_action( 'woocommerce_after_single_product', 'after_single_product' );

function after_single_product() {
	error_log( "after_single_product" );
}

I get this result:

MXgEgZ.png

As you can see, this sequence is not correct. The woocommerce_single_product_summary hook runs after the woocommerce_after_single_product_summary hook.

This is the execution sequence when the legacy template is active:

Jf2qsg.png

To reproduce

Steps to reproduce the behavior:

  1. Use the above snippet and take note of the execution sequence of the single product page hooks.

Expected behavior

The woocommerce_single_product_summary hook should run after the woocommerce_after_single_product_summary hook.

@jimjasson jimjasson added the type: bug The issue/PR concerns a confirmed bug. label Jul 27, 2023
@gigitux gigitux self-assigned this Aug 1, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Oct 1, 2023

This issue has been marked as stale because it has not seen any activity within the past 60 days. Our team uses this tool to help surface issues for review. If you are the author of the issue there's no need to comment as it will be looked at.

@github-actions github-actions bot added the status: stale Stale issues and PRs have had no updates for 60 days. label Oct 1, 2023
@gigitux gigitux removed the status: stale Stale issues and PRs have had no updates for 60 days. label Oct 5, 2023
@gigitux
Copy link
Contributor

gigitux commented Nov 27, 2023

Upon further consideration of this issue, I have decided to close it.
The sequence of hooks is contingent upon the order of blocks and how WordPress renders them. WordPress follows a rendering logic from the bottom to the top, rendering inner blocks before outer ones. Consequently, relying on a specific execution sequence of the hook is not feasible in this context.

@gigitux gigitux closed this as completed Nov 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug The issue/PR concerns a confirmed bug.
Projects
None yet
2 participants