Commit 84a0f08510d for woocommerce

commit 84a0f08510d0608a794f465c78216b48e120d772
Author: Fernando Espinosa <Ferdev@users.noreply.github.com>
Date:   Thu Oct 15 15:03:41 2026 +0200

    [WOOAIRR-295] Restore shipping ToS acceptance after activation (#68708)

    Fix shipping ToS acceptance after activation

diff --git a/plugins/woocommerce/changelog/wooairr-295-restore-shipping-tos-acceptance b/plugins/woocommerce/changelog/wooairr-295-restore-shipping-tos-acceptance
new file mode 100644
index 00000000000..20a0f7617d4
--- /dev/null
+++ b/plugins/woocommerce/changelog/wooairr-295-restore-shipping-tos-acceptance
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Record WooCommerce Shipping Terms of Service acceptance after installing and activating the extension.
diff --git a/plugins/woocommerce/client/admin/client/wp-admin-scripts/print-shipping-label-banner/shipping-banner/index.js b/plugins/woocommerce/client/admin/client/wp-admin-scripts/print-shipping-label-banner/shipping-banner/index.js
index 8db154d93a6..3631ab951d4 100644
--- a/plugins/woocommerce/client/admin/client/wp-admin-scripts/print-shipping-label-banner/shipping-banner/index.js
+++ b/plugins/woocommerce/client/admin/client/wp-admin-scripts/print-shipping-label-banner/shipping-banner/index.js
@@ -102,7 +102,12 @@ export class ShippingBanner extends Component {

 	async installAndActivatePlugins( pluginSlug ) {
 		// Avoid double activating.
-		const { installPlugins, activatePlugins, isRequesting } = this.props;
+		const {
+			installPlugins,
+			activatePlugins,
+			isRequesting,
+			isWcstCompatible,
+		} = this.props;
 		if ( isRequesting ) {
 			this.setState( { isShippingLabelButtonBusy: false } );
 			return false;
@@ -150,6 +155,20 @@ export class ShippingBanner extends Component {
 			return;
 		}

+		if ( isWcstCompatible ) {
+			try {
+				await acceptWcsTos();
+			} catch {
+				this.setState( {
+					setupErrorReason: setupErrorTypes.SETUP,
+					wcsSetupError: true,
+					isShippingLabelButtonBusy: false,
+					infoMessage: null,
+				} );
+				return;
+			}
+		}
+
 		this.setState( {
 			isPluginInstalledAndActivated: true,
 			isShippingLabelButtonBusy: false,
diff --git a/plugins/woocommerce/client/admin/client/wp-admin-scripts/print-shipping-label-banner/shipping-banner/test/index.js b/plugins/woocommerce/client/admin/client/wp-admin-scripts/print-shipping-label-banner/shipping-banner/test/index.js
index 7accd480805..07e3d58463f 100644
--- a/plugins/woocommerce/client/admin/client/wp-admin-scripts/print-shipping-label-banner/shipping-banner/test/index.js
+++ b/plugins/woocommerce/client/admin/client/wp-admin-scripts/print-shipping-label-banner/shipping-banner/test/index.js
@@ -249,6 +249,7 @@ describe( 'Create shipping label button', () => {
 				)
 			).toBeInTheDocument()
 		);
+		expect( acceptWcsTos ).toHaveBeenCalledTimes( 1 );

 		expect(
 			queryByText( /By clicking "Create shipping label"/i )
@@ -263,6 +264,45 @@ describe( 'Create shipping label button', () => {
 		expect( window.location.reload ).toHaveBeenCalledWith( true );
 	} );

+	it( 'should show a setup error when accepting the TOS after activation fails', async () => {
+		acceptWcsTos.mockRejectedValueOnce( new Error( 'API Error' ) );
+		const actionButtonLabel = 'Create shipping label';
+		const { getByRole, getByText, queryByRole } = render(
+			<ShippingBanner
+				isJetpackConnected={ true }
+				activatePlugins={ activatePlugins }
+				activePlugins={ [] }
+				installPlugins={ installPlugins }
+				isRequesting={ false }
+				itemsCount={ 1 }
+				orderId={ 1 }
+				isWcstCompatible={ true }
+				actionButtonLabel={ actionButtonLabel }
+			/>
+		);
+
+		await userEvent.click(
+			getByRole( 'button', {
+				name: actionButtonLabel,
+			} )
+		);
+
+		await waitFor( () =>
+			expect(
+				getByText(
+					'Unable to set up the plugin. Refresh the page and try again.'
+				)
+			).toBeInTheDocument()
+		);
+
+		expect(
+			getByRole( 'button', { name: actionButtonLabel } )
+		).not.toHaveClass( 'is-busy' );
+		expect(
+			queryByRole( 'button', { name: 'Reload page' } )
+		).not.toBeInTheDocument();
+	} );
+
 	it( 'should perform a request to accept the TOS and get WCS assets to load', async () => {
 		getWcsLabelPurchaseConfigs.mockReturnValueOnce( Promise.resolve( {} ) );
 		getWcsAssets.mockReturnValueOnce( Promise.resolve( {} ) );