Skip to content

Commit

Permalink
Add conditional check to replace launch-site task with LYS task (#1509)
Browse files Browse the repository at this point in the history
* Add conditional check to replace launch-site task with LYS task

* Changelog

* Merge add_tasks function with replace_tasks to consolidate logic and apply proper sorting

* Move logic around to simplify it more
  • Loading branch information
ilyasfoo authored Sep 6, 2024
1 parent aea181a commit 132f81c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
46 changes: 16 additions & 30 deletions includes/class-wc-calypso-bridge-setup-tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ private function __construct() {
// All plans.
add_action( 'load-woocommerce_page_wc-settings', array( $this, 'redirect_store_details_onboarding' ) );
add_action( 'wp_ajax_launch_store', array( $this, 'handle_ajax_launch_endpoint' ) );
add_action( 'init', array( $this, 'add_tasks' ) );
add_filter( 'woocommerce_admin_experimental_onboarding_tasklists', [ $this, 'replace_tasks' ] );
add_filter( 'get_user_metadata', array( $this, 'override_user_meta_field' ), 10, 4 );
}
Expand Down Expand Up @@ -86,14 +85,9 @@ public function handle_ajax_launch_endpoint() {
}

/**
* Add Setup Tasks.
* Add and replace setup tasks.
*/
public function add_tasks() {

if ( ! class_exists( '\Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists' ) ) {
return;
}

public function replace_tasks( $lists ) {
/**
* `ecommerce_custom_setup_tasks_enabled` filter.
*
Expand All @@ -104,27 +98,7 @@ public function add_tasks() {
* @param bool $status_enabled
* @return bool
*/
if ( ! (bool) apply_filters( 'ecommerce_custom_setup_tasks_enabled', true ) ) {
return;
}

$tl = \Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists::instance();
require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/tasks/class-wc-calypso-task-add-domain.php';
require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/tasks/class-wc-calypso-task-launch-site.php';

$list = $tl::get_lists_by_ids( array( 'setup' ) );
$list = array_pop( $list );

$add_domain_task = new \Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\AddDomain( $list );
$launch_site_task = new \Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\LaunchSite( $list );
$tl::add_task( 'setup', $add_domain_task );
$tl::add_task( 'setup', $launch_site_task );
}

/**
* Replace setup tasks.
*/
public function replace_tasks( $lists ) {
$ecommerce_custom_setup_tasks_enabled = (bool) apply_filters( 'ecommerce_custom_setup_tasks_enabled', true );
if ( isset( $lists['setup'] ) ) {
// Default product task index.
$product_task_index = 2;
Expand All @@ -142,7 +116,19 @@ public function replace_tasks( $lists ) {
unset( $lists['setup']->tasks[$index] );
break;
case 'launch-your-store':
if ( wc_calypso_bridge_is_trial_plan() ) {
if ( $ecommerce_custom_setup_tasks_enabled ) {
// Append add domain task before launch your store task.
require_once __DIR__ . '/tasks/class-wc-calypso-task-add-domain.php';
$add_domain_task = array( new \Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\AddDomain( $lists['setup'] ) );
array_splice( $lists['setup']->tasks, $index, 0, $add_domain_task );

// Replace launch your store task with launch site task.
if ( ! Features::is_enabled( 'launch-your-store' ) && ! wc_calypso_bridge_is_trial_plan() ) {
require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/tasks/class-wc-calypso-task-launch-site.php';
$launch_site_task = new \Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\LaunchSite( $lists['setup'] );
$lists['setup']->tasks[$index + 1] = $launch_site_task;
}
} else if ( wc_calypso_bridge_is_trial_plan() ) {
// Don't show launch your store task for trial sites.
unset( $lists['setup']->tasks[$index] );
}
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ This section describes how to install the plugin and get it working.
* Add sync coming soon status from LYS to WPCOM #1503
* Refactor LYS to use unidirectional data flow #1506
* Disable launch your store on trial sites #1507
* Add conditional check to replace launch-site task with LYS task #1509

= 2.5.5 =
* Add a new class to customize for Stripe from Partner Aware Onboarding #1492
Expand Down

0 comments on commit 132f81c

Please sign in to comment.