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
This commit is contained in:
Chi-Hsuan Huang 2024-10-21 07:22:16 +08:00 committed by GitHub
parent 3c076b5187
commit b5501426b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 87 additions and 0 deletions

View File

@ -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';

View File

@ -0,0 +1,68 @@
<?php
defined( 'ABSPATH' ) || exit;
register_woocommerce_admin_test_helper_rest_route(
'/tools/reset-launch-your-store',
'tools_reset_launch_your_store'
);
/**
* Reset Launch Your Store settings.
*
* This function resets the following:
* - Site visibility settings
* - Template changes
* - Survey completion state
* - Essential task list completion tracking
*
* @return bool True if the reset was successful, false otherwise.
*/
function tools_reset_launch_your_store() {
global $wpdb;
// Reset site visibility settings.
delete_option( 'woocommerce_coming_soon' );
delete_option( 'woocommerce_store_pages_only' );
delete_option( 'woocommerce_private_link' );
delete_option( 'woocommerce_share_key' );
$result = ( new \Automattic\WooCommerce\Admin\API\LaunchYourStore() )->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;
}

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Add tool to reset "Launch your store" and coming soon mode changes

View File

@ -115,4 +115,9 @@ export default [
description: <SetWccomBaseUrl />,
action: UPDATE_WCCOM_BASE_URL_ACTION_NAME,
},
{
command: 'Reset Launch Your Store',
description: 'Resets Launch Your Store and coming soon mode changes.',
action: 'resetLaunchYourStore',
},
];

View File

@ -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',
} );
} );
}