fix duplicate product set tool title #3247
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This change fixes a bug where the "Product sync" button and associated title were appearing twice on the Product Sync settings page (
wp-admin/admin.php?page=wc-facebook&tab=product_sync
) when enhanced onboarding is active.The root cause was identified in the
Enhanced_Settings
class. Its constructor was correctly instantiating the settings screen objects (includingSettings_Screens\Product_Sync
) and storing them in$this->screens
. However, it was also incorrectly hooking itsbuild_menu_item_array
method to theadmin_menu
action. This causedbuild_menu_item_array
to be executed a second time when theadmin_menu
action fired, leading to a second instantiation ofSettings_Screens\Product_Sync
.As a result, the constructor of
Settings_Screens\Product_Sync
(which adds WordPress actions for rendering custom setting fields likewoocommerce_admin_field_product_sync_title
) was running twice. This duplicated the action hook forrender_title
, causing the "Sync products" button and its surrounding elements (originally including an H2 title) to be rendered twice when WooCommerce processed that settings field.The fix removes the redundant
add_action( 'admin_menu', array( $this, 'build_menu_item_array' ) );
from theEnhanced_Settings
constructor. Thebuild_menu_item_array
method is now only called once at construction time to populate$this->screens
, ensuring that each settings screen (and its associated action hooks) is initialized only once.Type of change
Checklist
Changelog entry
Fix: Prevent duplicate "Product sync" button on settings page when enhanced onboarding is active.
Test Plan
wp-admin/admin.php?page=wc-facebook&tab=product_sync
.Screenshots
Enhanced_settings = true

Enhanced_settings = false (identical)

Broken state (previous)

Before
(Ideally, a screenshot showing the "Product sync" button and title appearing twice)
After
(Ideally, a screenshot showing the "Product sync" button and title appearing once after the fix)