Skip to content

Commit

Permalink
Disable launch your store on trial sites
Browse files Browse the repository at this point in the history
  • Loading branch information
chihsuan committed Aug 29, 2024
1 parent 1c78762 commit cdd7cf8
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 6 deletions.
1 change: 1 addition & 0 deletions class-wc-calypso-bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public function includes() {
require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/free-trial/partners/class-wc-calypso-bridge-partner-stripe.php';
require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/free-trial/partners/class-wc-calypso-bridge-partner-paypal.php';
require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/class-wc-calypso-bridge-coming-soon.php';
require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/class-wc-calypso-bridge-admin-settings.php';

// Experiments.
require_once WC_CALYPSO_BRIDGE_PLUGIN_PATH . '/includes/experiments/class-wc-calypso-bridge-task-list-reminderbar-experiment.php';
Expand Down
64 changes: 64 additions & 0 deletions includes/class-wc-calypso-bridge-admin-settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

defined( 'ABSPATH' ) || exit;

/**
* Class WC_Calypso_Bridge_Admin_Settings
*
* @since x.x.x
* @version x.x.x
*
* Handle Coming Soon mode.
*/
class WC_Calypso_Bridge_Admin_Settings {
/**
* The single instance of the class.
*
* @var WC_Calypso_Bridge_Admin_Settings
*/
protected static $instance = null;

/**
* Get class instance.
*
* @return object Instance.
*/
final public static function get_instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}

return self::$instance;
}

/**
* Constructor.
*/
public function __construct() {
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'replace_settings_tab' ), PHP_INT_MAX );
}

/**
* Replace the settings tab.
*
* @param array $tabs The tabs.
* @return array The tabs.
*/
public function replace_settings_tab( $tabs ) {
global $current_tab;

if ( wc_calypso_bridge_is_ecommerce_trial_plan() ) {
// Remove Site Visibility setting for the free trial plan.
unset( $tabs['site-visibility'] );

if ( isset( $current_tab ) && $current_tab === 'site-visibility' ) {
wp_safe_redirect( admin_url( 'admin.php?page=wc-settings' ) );
exit;
}
}

return $tabs;
}
}

WC_Calypso_Bridge_Admin_Settings::get_instance();
18 changes: 17 additions & 1 deletion includes/class-wc-calypso-bridge-coming-soon.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function __construct() {
add_filter( 'woocommerce_coming_soon_exclude', array( $this, 'should_exclude_lys_coming_soon' ) );
add_action( 'update_option_wpcom_public_coming_soon', array( $this, 'sync_coming_soon_wpcom_to_lys' ), 10, 3 );
$this->hook_update_option_woocommerce_coming_soon();
add_filter( 'option_woocommerce_coming_soon', array( $this, 'possibly_disable_lys_coming_soon' ), 10 );
}

/**
Expand All @@ -63,7 +64,8 @@ public function unhook_update_option_woocommerce_coming_soon() {
*/
public function should_show_a8c_coming_soon_page( $should_show ) {
if (
class_exists( '\Automattic\WooCommerce\Admin\Features\Features' ) && \Automattic\WooCommerce\Admin\Features\Features::is_enabled( 'launch-your-store' )
class_exists( '\Automattic\WooCommerce\Admin\Features\Features' ) && \Automattic\WooCommerce\Admin\Features\Features::is_enabled( 'launch-your-store' ) &&
! wc_calypso_bridge_is_ecommerce_trial_plan()
) {
return false;
}
Expand Down Expand Up @@ -178,6 +180,20 @@ public function add_admin_notice( $message, $notice_type = 'info' ) {
<?php
} );
}

/**
* Disable the coming soon page if the user is on the free trial plan.
*
* @param string $value
* @return string
*/
public function possibly_disable_lys_coming_soon( $value ) {
if ( wc_calypso_bridge_is_ecommerce_trial_plan() ) {
return 'no';
}

return $value;
}
}

WC_Calypso_Bridge_Coming_Soon::get_instance();
8 changes: 7 additions & 1 deletion includes/class-wc-calypso-bridge-setup-tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @package WC_Calypso_Bridge/Classes
* @since 2.0.0
* @version 2.3.3
* @version x.x.x
*/

defined( 'ABSPATH' ) || exit;
Expand Down Expand Up @@ -141,6 +141,12 @@ public function replace_tasks( $lists ) {
// Remove appearance and purchase task.
unset( $lists['setup']->tasks[$index] );
break;
case 'launch-your-store':
if ( wc_calypso_bridge_is_ecommerce_trial_plan() ){
// Remove launch your store task.
unset( $lists['setup']->tasks[$index] );
}
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,7 @@ public function filter_wc_admin_enabled_features( $features ) {
* @return array
*/
public function filter_woocommerce_admin_features( $features ) {
// Disable launch-your-store to prevent clashes with similar functionality already provided.
if ( isset( $features['launch-your-store'] ) ) {
$features['launch-your-store'] = false;
}


// The rest applies only to Entrepreneur and Woo Express plans.
if ( ! wc_calypso_bridge_has_ecommerce_features() ) {
Expand Down

0 comments on commit cdd7cf8

Please sign in to comment.