From 891ecb7efb9ee7ae698ac09a18b9ce011e3ca843 Mon Sep 17 00:00:00 2001 From: Joshua T Flowers Date: Thu, 12 Jan 2023 11:02:40 -0800 Subject: [PATCH] Redirect to new product experience when in experiment group (#36381) * Redirect to new product experience when in experiment group * Add changelog entry --- .../products/use-create-product-by-type.ts | 18 ++++++++++++++++++ .../add-76-product-creation-experiment | 4 ++++ 2 files changed, 22 insertions(+) create mode 100644 plugins/woocommerce/changelog/add-76-product-creation-experiment diff --git a/plugins/woocommerce-admin/client/tasks/fills/products/use-create-product-by-type.ts b/plugins/woocommerce-admin/client/tasks/fills/products/use-create-product-by-type.ts index 6232c08b688..080722aed7c 100644 --- a/plugins/woocommerce-admin/client/tasks/fills/products/use-create-product-by-type.ts +++ b/plugins/woocommerce-admin/client/tasks/fills/products/use-create-product-by-type.ts @@ -4,6 +4,9 @@ import { useDispatch } from '@wordpress/data'; import { ITEMS_STORE_NAME } from '@woocommerce/data'; import { getAdminLink } from '@woocommerce/settings'; +import { getNewPath, navigateTo } from '@woocommerce/navigation'; +import { loadExperimentAssignment } from '@woocommerce/explat'; +import moment from 'moment'; import { useState } from '@wordpress/element'; /** @@ -25,6 +28,21 @@ export const useCreateProductByType = () => { } setIsRequesting( true ); + + if ( type === 'physical' ) { + const momentDate = moment().utc(); + const year = momentDate.format( 'YYYY' ); + const month = momentDate.format( 'MM' ); + const assignment = await loadExperimentAssignment( + `woocommerce_product_creation_experience_${ year }${ month }_v1` + ); + + if ( assignment.variationName === 'treatment' ) { + navigateTo( { url: getNewPath( {}, '/add-product', {} ) } ); + return; + } + } + try { const data: { id?: number; diff --git a/plugins/woocommerce/changelog/add-76-product-creation-experiment b/plugins/woocommerce/changelog/add-76-product-creation-experiment new file mode 100644 index 00000000000..70af2275260 --- /dev/null +++ b/plugins/woocommerce/changelog/add-76-product-creation-experiment @@ -0,0 +1,4 @@ +Significance: minor +Type: tweak + +Redirect to new product experience when in experiment group