Skip to content

fix duplicate product set tool title #3247

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sol-loup
Copy link
Contributor

@sol-loup sol-loup commented May 27, 2025

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 (including Settings_Screens\Product_Sync) and storing them in $this->screens. However, it was also incorrectly hooking its build_menu_item_array method to the admin_menu action. This caused build_menu_item_array to be executed a second time when the admin_menu action fired, leading to a second instantiation of Settings_Screens\Product_Sync.

As a result, the constructor of Settings_Screens\Product_Sync (which adds WordPress actions for rendering custom setting fields like woocommerce_admin_field_product_sync_title) was running twice. This duplicated the action hook for render_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 the Enhanced_Settings constructor. The build_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

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have commented my code, particularly in hard-to-understand areas. (Comment existed prior to change)
  • I have confirmed that my changes do not introduce any new PHPCS warnings or errors. (Assumed based on the nature of the fix)
  • I have checked plugin debug logs that my changes do not introduce any new PHP warnings or FATAL errors. (Assumed based on the nature of the fix)
  • I followed general Pull Request best practices.
  • [] I have added tests (if necessary) and all the new and existing unit tests pass locally with my changes. (Test might be needed to cover this specific admin UI rendering logic)
  • I have completed dogfooding and QA testing, or I have conducted thorough due diligence to ensure that it does not break existing functionality. (Change is minor and targeted)
  • [] I have updated or requested update to plugin documentations (if necessary). (Likely not necessary for this internal fix)

Changelog entry

Fix: Prevent duplicate "Product sync" button on settings page when enhanced onboarding is active.

Test Plan

  1. Ensure the "Enhanced Onboarding" mode is active for the Facebook for WooCommerce plugin.
  2. Navigate to the WooCommerce Facebook settings page, specifically the "Product sync" tab: wp-admin/admin.php?page=wc-facebook&tab=product_sync.
  3. Before the change: Observe that the "Product sync" title/area and the "Sync products" button are rendered twice on the page.
  4. Apply the change.
  5. After the change: Refresh the "Product sync" settings page.
  6. Verify that the "Product sync" title/area and the "Sync products" button are now rendered only once.
  7. Verify that other tabs and settings functionalities remain unaffected.

Screenshots

Enhanced_settings = true
Screenshot 2025-05-27 at 9 47 19 AM

Enhanced_settings = false (identical)
Screenshot 2025-05-27 at 9 47 27 AM

Broken state (previous)
Screenshot 2025-05-27 at 9 49 02 AM

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)

@facebook-github-bot
Copy link
Contributor

@sol-loup has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

📦 Latest Plugin Build

Built at: 2025-05-27T16:51:01.478Z
Commit: 215e137
Size: 1.1M

Download: Click here to download the plugin

To download: Click the link above → Scroll to bottom → Download "facebook-for-woocommerce" artifact

@facebook-github-bot
Copy link
Contributor

@sol-loup has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@sharunaanandraj
Copy link
Contributor

@sol-loup Fixing this here #3246

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants