Skip to content

Commit

Permalink
Add is_trial_plan()
Browse files Browse the repository at this point in the history
- Update trial plan checks
  • Loading branch information
chihsuan committed Sep 3, 2024
1 parent b524143 commit 5f5352d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 deletions.
65 changes: 65 additions & 0 deletions class-wc-calypso-bridge-dotcom-features.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ function wc_calypso_bridge_is_woo_express_plan() {
}
}

if ( ! function_exists( 'wc_calypso_bridge_is_trial_plan' ) ) {
/**
* Returns if a site is a trial plan site or not.
*
* @since x.x.x
*
* @return bool True if the site is a trial plan.
*/
function wc_calypso_bridge_is_trial_plan() {
return WC_Calypso_Bridge_DotCom_Features::is_trial_plan();
}
}

/**
* WC Calypso Bridge DotCom Features class.
*/
Expand Down Expand Up @@ -182,6 +195,13 @@ class WC_Calypso_Bridge_DotCom_Features {
*/
protected static $is_business_plan = null;

/**
* Is Trial plan.
*
* @var bool
*/
protected static $is_trial_plan = null;

/**
* Determine if site has a WordPress.com eCommerce plan and cache the result.
*
Expand Down Expand Up @@ -340,4 +360,49 @@ public static function is_business_plan() {

return self::$is_business_plan;
}

public static function is_trial_plan() {
if ( is_null( self::$is_trial_plan ) ) {
self::$is_trial_plan = self::is_ecommerce_trial_plan()
// Business trial plans
|| self::has_plan( 'wp-bundle-hosting-trial', true )
|| self::has_plan( 'wp-bundle-migration-trial', true );
}

return self::$is_trial_plan;
}

/**
* Check if the site has a specific plan.
*
* @param string $plan The plan to check for.
* @param bool $exact_one_plan If true, the site must have exactly one plan.
*
* @return bool True if the site has the plan, false otherwise.
*/
private static function has_plan( $plan, $exact_one_plan = false ) {
if ( ! function_exists( 'wpcom_get_site_purchases' ) ) {
return false;
}

$all_site_purchases = wpcom_get_site_purchases();
if ( ! is_array( $all_site_purchases ) ) {
return false;
}

$bundles = wp_list_filter( $all_site_purchases, array( 'product_type' => 'bundle' ) );

if ( $exact_one_plan && count( $bundles ) !== 1 ) {
return false;
}

foreach ( $bundles as $bundle ) {
if ( isset( $bundle->billing_product_slug ) && $bundle->billing_product_slug === $plan ) {
return true;
}
}

return false;
}

}
6 changes: 5 additions & 1 deletion includes/class-wc-calypso-bridge-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ final public static function get_instance() {
* Constructor.
*/
public function __construct() {
if ( ! is_admin() ) {
return;
}

add_filter( 'woocommerce_settings_tabs_array', array( $this, 'replace_settings_tab' ), PHP_INT_MAX );
}

Expand All @@ -47,7 +51,7 @@ public function __construct() {
public function replace_settings_tab( $tabs ) {
global $current_tab;

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

Expand Down
2 changes: 1 addition & 1 deletion includes/class-wc-calypso-bridge-coming-soon.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function should_exclude_lys_coming_soon( $exclude ) {
*/
public function override_option_woocommerce_coming_soon( $current_value ) {
// Turn off coming soon mode for trial plan.
if ( wc_calypso_bridge_is_ecommerce_trial_plan() ) {
if ( wc_calypso_bridge_is_trial_plan() ) {
return 'no';
}

Expand Down
4 changes: 2 additions & 2 deletions includes/class-wc-calypso-bridge-setup-tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ public function replace_tasks( $lists ) {
unset( $lists['setup']->tasks[$index] );
break;
case 'launch-your-store':
if ( wc_calypso_bridge_is_ecommerce_trial_plan() ){
// Remove launch your store task.
if ( wc_calypso_bridge_is_trial_plan() ) {
// Don't show launch your store task for trial sites.
unset( $lists['setup']->tasks[$index] );
}
break;
Expand Down

0 comments on commit 5f5352d

Please sign in to comment.