Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Subscriptions with WooPayments eligibility as we move to deprecate this functionality #7238

Merged
merged 18 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
a9d7391
Increase the requirements to determine ifstore is eligible for free w…
mattallan Sep 4, 2023
7881375
Change the logic to only show wcpay subs setting in a deprecated way
mattallan Sep 4, 2023
866a18d
Merge branch 'develop' into issue/6510-deprecate-wcpay-subscriptions
mattallan Sep 6, 2023
64623fe
Add changelog entry
mattallan Sep 6, 2023
21795aa
Update logic which determines if a store is eligible for wcpay subscr…
james-allan Sep 11, 2023
a373e5d
Update function name
james-allan Sep 11, 2023
8184c55
fix docblock typos
mattallan Sep 11, 2023
5a1afde
Merge branch 'develop' into issue/6510-deprecate-wcpay-subscriptions
james-allan Sep 11, 2023
8d08d73
Merge branch 'develop' into issue/6510-deprecate-wcpay-subscriptions
james-allan Sep 11, 2023
8d3a3e6
Merge branch 'develop' into issue/6510-deprecate-wcpay-subscriptions
james-allan Sep 11, 2023
cd40503
Use wcpay settings instance of subscriptions plugin active variable
james-allan Sep 11, 2023
c18545c
Merge branch 'develop' into issue/6510-deprecate-wcpay-subscriptions
james-allan Sep 20, 2023
33d24b5
Merge branch 'develop' into issue/6510-deprecate-wcpay-subscriptions
james-allan Sep 26, 2023
222676e
Disable the wcpay subscriptions feature if you have woo subscriptions…
james-allan Sep 26, 2023
7acd20e
Merge branch 'develop' into issue/6510-deprecate-wcpay-subscriptions
james-allan Sep 27, 2023
80d18c0
Merge branch 'develop' into issue/6510-deprecate-wcpay-subscriptions
james-allan Oct 3, 2023
0e8dfb6
Move the disabling of wcpay subscriptions on update to main payments …
mattallan Oct 4, 2023
385e2f8
Merge branch 'develop' into issue/6510-deprecate-wcpay-subscriptions
james-allan Oct 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/issue-6510-deprecate-wcpay-subscriptions
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: update

Only display the WCPay Subscriptions setting to existing users as part of deprecating this feature.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const WCPaySubscriptionsToggle = () => {
* for wcpay subscriptions or if wcpay subscriptions are already enabled.
*/
return ! wcpaySettings.isSubscriptionsActive &&
( isWCPaySubscriptionsEligible || isWCPaySubscriptionsEnabled ) ? (
isWCPaySubscriptionsEligible ? (
<CheckboxControl
label={ sprintf(
/* translators: %s: WooPayments */
Expand Down
65 changes: 60 additions & 5 deletions includes/class-wc-payments-features.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,72 @@ public static function is_wcpay_subscriptions_enabled() {
}

/**
* Returns whether WCPay Subscriptions is eligible, based on the stores base country.
* Returns whether the store is eligible to use WCPay Subscriptions (the free subscriptions bundled in WooPayments)
*
* Stores are eligible for the WCPay Subscriptions feature if:
* 1. The store has existing WCPay Subscriptions, or
* 2. The store has Stripe Billing product metadata on at least 1 product subscription product.
*
* @return bool
*/
public static function is_wcpay_subscriptions_eligible() {
if ( ! function_exists( 'wc_get_base_location' ) ) {
return false;
/**
* Check if they have at least 1 WCPay Subscription.
*
* Note: this is only possible if WCPay Subscriptions is enabled, otherwise the wcs_get_subscriptions function wouldn't exist.
*/
if ( function_exists( 'wcs_get_subscriptions' ) ) {
$wcpay_subscriptions = wcs_get_subscriptions(
[
'subscriptions_per_page' => 1,
'subscription_status' => 'any',
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
[
'key' => '_wcpay_subscription_id',
'compare' => 'EXISTS',
],
],
]
);

if ( count( $wcpay_subscriptions ) > 0 ) {
return true;
}
}

$store_base_location = wc_get_base_location();
return ! empty( $store_base_location['country'] ) && 'US' === $store_base_location['country'];
/**
* Check if they have at least 1 Stripe Billing enabled product.
*/
$stripe_billing_meta_query_handler = function ( $query, $query_vars ) {
if ( ! empty( $query_vars['stripe_billing_product'] ) ) {
$query['meta_query'][] = [
'key' => '_wcpay_product_hash',
'compare' => 'EXISTS',
];
}

return $query;
};

add_filter( 'woocommerce_product_data_store_cpt_get_products_query', $stripe_billing_meta_query_handler, 10, 2 );

$subscription_products = wc_get_products(
[
'limit' => 1,
'type' => [ 'subscription', 'variable-subscription' ],
'status' => 'publish',
'return' => 'ids',
'stripe_billing_product' => 'true',
]
);

remove_filter( 'woocommerce_product_data_store_cpt_get_products_query', $stripe_billing_meta_query_handler, 10, 2 );

if ( count( $subscription_products ) > 0 ) {
return true;
}

return false;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,8 @@ public static function init() {
add_action( 'woocommerce_onboarding_profile_data_updated', 'WC_Payments_Features::maybe_enable_wcpay_subscriptions_after_onboarding', 10, 2 );
}

add_action( 'woocommerce_woocommerce_payments_updated', [ __CLASS__, 'maybe_disable_wcpay_subscriptions_on_update' ] );

add_action( 'rest_api_init', [ __CLASS__, 'init_rest_api' ] );
add_action( 'woocommerce_woocommerce_payments_updated', [ __CLASS__, 'set_plugin_activation_timestamp' ] );

Expand Down Expand Up @@ -1780,4 +1782,15 @@ private static function should_load_stripe_billing_integration() {
)
);
}

/**
* Disable the WCPay Subscriptions feature on WooPayments plugin update if it's enabled and the store is no longer eligible.
*
* @see WC_Payments_Features::is_wcpay_subscriptions_eligible() for eligibility criteria.
*/
public static function maybe_disable_wcpay_subscriptions_on_update() {
if ( WC_Payments_Features::is_wcpay_subscriptions_enabled() && ( class_exists( 'WC_Subscriptions' ) || ! WC_Payments_Features::is_wcpay_subscriptions_eligible() ) ) {
update_option( WC_Payments_Features::WCPAY_SUBSCRIPTIONS_FLAG_NAME, '0' );
}
}
}
Loading