Skip to content

Set up checkout and publish the shop after the Commerce Partner Integration install completes - #4090

Open
jczhuoMeta wants to merge 5 commits into
mainfrom
feature/fbl4b-checkout-setup
Open

jczhuoMeta wants to merge 5 commits into
mainfrom
feature/fbl4b-checkout-setup

Conversation

@jczhuoMeta

@jczhuoMeta jczhuoMeta commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

When a store onboards through Facebook Login for Business, Meta no longer sets up checkout for it during onboarding. The plugin now does this itself after the Commerce Partner Integration (CPI) install completes.

Once POST /commerce-partner-integrations/finalize-install succeeds, Settings\Handler::handle_finalize_install() calls the Graph API once:

POST /{commerce_merchant_settings_id}
checkout_config = {
  "checkout_url": "<home_url>/checkout-link/",
  "country_code": "<store base country>",
  "publish_shop": true
}
  • Checkout URL: WooCommerce core's native /checkout-link/ endpoint, the same URL Meta's checkout already sends buyers to (see Remove unused /fb-checkout endpoint; Meta checkout calls WooCommerce's /checkout-link (WC 10.0+) #4082). Meta appends the cart to the query string. It is built from home_url(), the site address, because /checkout-link/ is a front-end rewrite rule. site_url() would point inside the WordPress directory on stores that install WordPress in a subdirectory.
  • Country: the store's WooCommerce base country (WC()->countries->get_base_country()). The store is the source of truth: this is the same value the plugin already pushes to the CPI as country_code, so it is not read back from Meta.
  • publish_shop: true: Meta also publishes the shop. Without it, the endpoint only publishes for some partner platforms.

Skipped quietly (no call, no log) when:

  • finalize-install failed and the legacy install message was used instead;
  • there is no Commerce Merchant Settings ID.

Skipped and logged as skipped when:

  • the store has no base country;
  • the site uses plain permalinks, because /checkout-link/ is a rewrite rule and does not route without pretty permalinks;
  • WooCommerce is older than 10.0, because /checkout-link/ does not exist there.

Failure handling: a failed call never fails the install. Both Graph errors and transport errors are caught, and every attempted outcome is logged as commerce_merchant_settings_checkout_setup (success, skipped or failed) with the CMS ID, country, checkout URL sent, whether pretty permalinks are on, WooCommerce version and any error. There is no automatic retry.

Known limitation: like any other Graph call made through API, a 200-range permission error from this request sets the wc_facebook_connection_invalid flag.

Added

  • API\CommerceMerchantSettings\Checkout\Request
  • API::set_up_checkout()

Internal tracking: T292693512

Type of change

  • Add (non-breaking change which adds functionality)

Checklist

  • I have commented my code, particularly in hard-to-understand areas, if any.
  • I have confirmed that my changes do not introduce any new PHPCS warnings or errors.
  • I have checked plugin debug logs that my changes do not introduce any new PHP warnings or FATAL errors.
  • 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.
  • I have completed dogfooding and QA testing, or I have conducted thorough due diligence to ensure that it does not break existing functionality.
  • I have updated or requested update to plugin documentations (if necessary). No documentation change is needed.

Changelog entry

Set up checkout and publish the shop after the Commerce Partner Integration install completes.

Test Plan

Automated

New cases in HandlerFinalizeInstallTest. They intercept the Graph request, so the real request payload is asserted.

  • Success: a successful finalize sends one POST /{cms_id} with checkout_config (home_url('/checkout-link/'), the store's base country, publish_shop: true) and logs success.
  • Subdirectory install: with the WordPress address at /wp and the site address at the root, the checkout URL uses the site address.
  • Plain permalinks: no request is sent and skipped is logged with pretty_permalinks: false.
  • Country: the store's base country is sent even when the finalize-install response carries a different country_code, and checkout is skipped and logged when the store has no base country.
  • Skip: with no Commerce Merchant Settings ID, no request is sent and nothing is logged.
  • Failure: a Graph error response and a transport error are each logged as failed with the error, and the install still returns 200.
  • Fallback install: a failed finalize-install (legacy fallback) sends no checkout request.

Other checks:

  • PHPCS (phpcs.xml.dist), PHPCompatibilityWP (PHP 7.4+), php -l and git diff --check: clean.
  • Full unit and integration suites run locally on the current head: no new failures against main.

Manual verification (required before release)

On a test store allowlisted for Facebook Login for Business onboarding, running WooCommerce 10.0+ with debug logging enabled:

  1. Onboard from Marketing > Facebook through Facebook Login for Business with the Commerce add-on. Set the store's base country (WooCommerce > Settings > General) to a supported checkout country first, for example US.
  2. In the WooCommerce logs, confirm one POST /{commerce_merchant_settings_id} with checkout_config and a commerce_merchant_settings_checkout_setup log with success.
  3. In Commerce Manager, confirm that the checkout URL for that country is <site>/checkout-link/ and that the Facebook and Instagram shops are published.
  4. Add a product to cart from the shop and confirm that checkout lands on the store's WooCommerce checkout with the cart filled.

QA results

Local WordPress store (WordPress 7.1.2, WooCommerce 11.1.2, PHP 8.2.30), 2026-10-13.

These results are from the first revision. Since then the checkout URL uses home_url(), the country is the store's base country, plain permalinks are skipped, and a missing CMS ID is skipped without a log. The manual steps above will be re-run on the current head. The PHP debug log had no new warnings or fatal errors during any of the checks below, including heartbeats run through WP-Cron.

  • Onboarding through Facebook Login for Business (US). finalize-install succeeded, then POST /{cms_id} was sent with {"checkout_config":{"checkout_url":"http://localhost:10005/checkout-link/","country_code":"US","publish_shop":true}} and Meta returned 200 {"success":true}.
  • Outcome log. commerce_merchant_settings_checkout_setup was logged as success, with the checkout URL, the country and the WooCommerce version.
  • Meta-side state. Reading back the Commerce Merchant Settings: checkout_config(US) is http://localhost:10005/checkout-link/, offsite_iab_checkout_enabled_countries is ["US"], and the Facebook shop sales channel is ENABLED.
  • Checkout link. /checkout-link/?products=<id>:1 redirects (302) to /checkout/ with the cart filled.
  • Buyer checkout from a Meta shop. Still to do on a publicly reachable HTTPS store; a localhost store cannot be reached by Meta.

Screenshots

Not applicable; this change has no user-interface impact.

@jczhuoMeta jczhuoMeta added the changelog: add A new feature, function, or functionality was added. label Oct 13, 2026
@meta-cla meta-cla Bot added the CLA Signed label Oct 13, 2026
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

📦 Latest Plugin Build

Built at: 2026-11-05T10:26:11Z
Commit: 8f5e09c
Size: 1.9M

Download: Click here to download the plugin

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

@jczhuoMeta
jczhuoMeta marked this pull request as ready for review October 13, 2026 22:51
@meta-codesync

meta-codesync Bot commented Oct 14, 2026

Copy link
Copy Markdown

@jczhuoMeta has imported this pull request. If you are a Meta employee, you can view this in D125257085.

@codecov-commenter

codecov-commenter commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 62 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@08164c9). Learn more about missing BASE report.

Files with missing lines Patch % Lines
includes/API/Plugin/Settings/Handler.php 0.00% 43 Missing ⚠️
.../API/CommerceMerchantSettings/Checkout/Request.php 0.00% 12 Missing ⚠️
includes/API.php 0.00% 4 Missing ⚠️
...udes/API/CommerceIntegration/Finalize/Response.php 0.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4090   +/-   ##
=======================================
  Coverage        ?   11.08%           
  Complexity      ?     6140           
=======================================
  Files           ?      236           
  Lines           ?    20840           
  Branches        ?        0           
=======================================
  Hits            ?     2311           
  Misses          ?    18529           
  Partials        ?        0           
Flag Coverage Δ
integration 11.08% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…ration install completes

Onboarding through Facebook Login for Business no longer sets up checkout
on Meta's side, so the plugin does it once finalize-install succeeds. It
calls POST /{commerce_merchant_settings_id} with checkout_config: the
store's WooCommerce /checkout-link/ URL, the integration's country from
the finalize-install response (the store's base country when it has
none), and publish_shop set so the shop is published.

The call runs only after a successful finalize-install, never fails the
install, and logs its outcome. It is skipped without a Commerce Merchant
Settings ID, without a country, or on WooCommerce older than 10.0, which
does not serve /checkout-link/.
Stores without debug logging only see the outcome log, so record the
checkout URL there too; it shows what was sent to Meta, including its
scheme and host.
…gs ID

Return before the Graph call and the outcome log, so stores without a CMS
no longer queue a 'skipped' checkout setup log. The country and WooCommerce
version skips still log 'skipped'.
/checkout-link/ is a WooCommerce front-end rewrite rule. site_url() points
inside the WordPress directory on subdirectory installs, and the rule never
routes without pretty permalinks, so either case would publish the shop with
a checkout URL that 404s. Use home_url(), skip (logged as 'skipped') on plain
permalinks, and log whether pretty permalinks are on.
The store owns its country: the plugin already pushes
WC()->countries->get_base_country() to the Commerce Partner Integration as
country_code. Reading it back from the finalize-install response was circular,
so use the base country directly and drop the response's country_code parsing.
@vahidkay-meta
vahidkay-meta force-pushed the feature/fbl4b-checkout-setup branch from 54bf699 to 99452ae Compare November 5, 2026 10:25

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: add A new feature, function, or functionality was added. CLA Signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants