From b5501426b44eb9f3ce62865615e5b34193ff7f27 Mon Sep 17 00:00:00 2001 From: Chi-Hsuan Huang Date: Mon, 21 Oct 2024 07:22:16 +0800 Subject: [PATCH] Add tool to reset "Launch your store" and coming soon mode changes (#52149) * Add tool to reset "Launch your store" and coming soon mode changes * Update docs * Update docs * Address PR feedback --- plugins/woocommerce-beta-tester/api/api.php | 1 + .../api/tools/reset-launch-your-store.php | 68 +++++++++++++++++++ .../changelog/add-reset-lys-tool | 4 ++ .../src/tools/commands/index.js | 5 ++ .../src/tools/data/actions.js | 9 +++ 5 files changed, 87 insertions(+) create mode 100644 plugins/woocommerce-beta-tester/api/tools/reset-launch-your-store.php create mode 100644 plugins/woocommerce-beta-tester/changelog/add-reset-lys-tool diff --git a/plugins/woocommerce-beta-tester/api/api.php b/plugins/woocommerce-beta-tester/api/api.php index 01091b7e92a..a43fe3d71b7 100644 --- a/plugins/woocommerce-beta-tester/api/api.php +++ b/plugins/woocommerce-beta-tester/api/api.php @@ -67,3 +67,4 @@ require 'remote-inbox-notifications/class-wca-test-helper-remote-inbox-notificat require 'remote-logging/remote-logging.php'; require 'tools/wccom-request-errors.php'; require 'tools/set-wccom-base-url.php'; +require 'tools/reset-launch-your-store.php'; diff --git a/plugins/woocommerce-beta-tester/api/tools/reset-launch-your-store.php b/plugins/woocommerce-beta-tester/api/tools/reset-launch-your-store.php new file mode 100644 index 00000000000..45081cd4a3d --- /dev/null +++ b/plugins/woocommerce-beta-tester/api/tools/reset-launch-your-store.php @@ -0,0 +1,68 @@ +initialize_coming_soon(); + if ( ! $result ) { + return new WP_Error( 'initialization_failed', 'Failed to initialize coming soon mode.' ); + } + + // Remove template changes. + $template = get_block_template( 'woocommerce/woocommerce//coming-soon', 'wp_template' ); + if ( $template && isset( $template->wp_id ) ) { + $delete_result = wp_delete_post( $template->wp_id, true ); + if ( false === $delete_result ) { + return new WP_Error( 'template_deletion_failed', 'Failed to delete the coming soon template.' ); + } + } + + // Reset survey completion state. + delete_option( 'woocommerce_admin_launch_your_store_survey_completed' ); + + // Reset essential task list completion tracking. + $tasks_completed = get_option( \Automattic\WooCommerce\Admin\Features\OnboardingTasks\Task::COMPLETED_OPTION, array() ); + $tasks_completed = array_filter( + $tasks_completed, + function( $task ) { + return 'launch-your-store' !== $task; + } + ); + update_option( \Automattic\WooCommerce\Admin\Features\OnboardingTasks\Task::COMPLETED_OPTION, $tasks_completed ); + + // Reset setup task list completion tracking. + $task_lists_completed = get_option( \Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskList::COMPLETED_OPTION, array() ); + $task_lists_completed = array_filter( + $task_lists_completed, + function( $task_list ) { + return 'setup' !== $task_list; + } + ); + update_option( \Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskList::COMPLETED_OPTION, $task_lists_completed ); + + return true; +} diff --git a/plugins/woocommerce-beta-tester/changelog/add-reset-lys-tool b/plugins/woocommerce-beta-tester/changelog/add-reset-lys-tool new file mode 100644 index 00000000000..afb630712ef --- /dev/null +++ b/plugins/woocommerce-beta-tester/changelog/add-reset-lys-tool @@ -0,0 +1,4 @@ +Significance: minor +Type: add + +Add tool to reset "Launch your store" and coming soon mode changes diff --git a/plugins/woocommerce-beta-tester/src/tools/commands/index.js b/plugins/woocommerce-beta-tester/src/tools/commands/index.js index 55d8b18df6d..430e59fa3b3 100644 --- a/plugins/woocommerce-beta-tester/src/tools/commands/index.js +++ b/plugins/woocommerce-beta-tester/src/tools/commands/index.js @@ -115,4 +115,9 @@ export default [ description: , action: UPDATE_WCCOM_BASE_URL_ACTION_NAME, }, + { + command: 'Reset Launch Your Store', + description: 'Resets Launch Your Store and coming soon mode changes.', + action: 'resetLaunchYourStore', + }, ]; diff --git a/plugins/woocommerce-beta-tester/src/tools/data/actions.js b/plugins/woocommerce-beta-tester/src/tools/data/actions.js index 8f138a3874c..e988cc653f5 100644 --- a/plugins/woocommerce-beta-tester/src/tools/data/actions.js +++ b/plugins/woocommerce-beta-tester/src/tools/data/actions.js @@ -317,3 +317,12 @@ export function* updateWccomBaseUrl( { url } ) { } ); } ); } + +export function* resetLaunchYourStore() { + yield runCommand( 'Reset Launch Your Store', function* () { + yield apiFetch( { + path: API_NAMESPACE + '/tools/reset-launch-your-store', + method: 'POST', + } ); + } ); +}