Skip to content

Commit 7b90664

Browse files
rtiohtdat
andauthored
Add notice when using bundled subscriptions (#10842)
Co-authored-by: Dat Hoang <[email protected]>
1 parent b8ab68c commit 7b90664

6 files changed

+457
-43
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: add
3+
4+
Show an admin notice when bundled subscriptions are in use

includes/class-wc-payments.php

Lines changed: 83 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -749,17 +749,26 @@ function () {
749749

750750
$wcpay_order_frt_meta_box = new WCPay\Fraud_Prevention\Order_Fraud_And_Risk_Meta_Box( self::$order_service );
751751
$wcpay_order_frt_meta_box->init_hooks();
752+
753+
// Initialize Stripe Billing deprecation notices.
754+
include_once WCPAY_ABSPATH . '/includes/subscriptions/class-wc-payments-subscriptions-admin-notices.php';
755+
$wcpay_subscriptions_admin_notices = new WC_Payments_Subscriptions_Admin_Notices();
756+
$wcpay_subscriptions_admin_notices->init_hooks();
752757
}
753758

754759
// Load Stripe Billing subscription integration.
755760
include_once WCPAY_ABSPATH . '/includes/subscriptions/class-wc-payments-subscriptions.php';
756761
WC_Payments_Subscriptions::init( self::$api_client, self::$customer_service, self::$order_service, self::$account, self::$token_service );
757762

763+
// Add hook to remove Stripe Billing deprecation note when WooCommerce Subscriptions is installed.
764+
add_action( 'activated_plugin', [ __CLASS__, 'maybe_remove_stripe_billing_deprecation_note' ], 10, 1 );
765+
758766
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '7.9.0', '<' ) ) {
759767
add_action( 'woocommerce_onboarding_profile_data_updated', 'WC_Payments_Features::maybe_enable_wcpay_subscriptions_after_onboarding', 10, 2 );
760768
}
761769

762770
add_action( 'woocommerce_woocommerce_payments_updated', [ __CLASS__, 'maybe_disable_wcpay_subscriptions_on_update' ] );
771+
add_action( 'woocommerce_woocommerce_payments_updated', [ __CLASS__, 'maybe_update_stripe_billing_deprecation_note' ] );
763772

764773
add_action( 'rest_api_init', [ __CLASS__, 'init_rest_api' ] );
765774
add_action( 'woocommerce_woocommerce_payments_updated', [ __CLASS__, 'set_plugin_activation_timestamp' ] );
@@ -1028,25 +1037,6 @@ public static function create_api_client() {
10281037
);
10291038
}
10301039

1031-
/**
1032-
* Create the HTTP instantiation.
1033-
*
1034-
* @return WC_Payments_Http_Interface
1035-
*/
1036-
private static function get_wc_payments_http() {
1037-
require_once __DIR__ . '/wc-payment-api/class-wc-payments-http-interface.php';
1038-
require_once __DIR__ . '/wc-payment-api/class-wc-payments-http.php';
1039-
1040-
$http_class = apply_filters( 'wc_payments_http', null );
1041-
1042-
if ( ! $http_class instanceof WC_Payments_Http_Interface ) {
1043-
$http_class = new WC_Payments_Http( new Automattic\Jetpack\Connection\Manager( 'woocommerce-payments' ) );
1044-
$http_class->init_hooks();
1045-
}
1046-
1047-
return $http_class;
1048-
}
1049-
10501040
/**
10511041
* Initialize the REST API controllers.
10521042
*/
@@ -1525,6 +1515,9 @@ public static function add_woo_admin_notes() {
15251515
require_once WCPAY_ABSPATH . 'includes/notes/class-wc-payments-notes-set-up-stripelink.php';
15261516
WC_Payments_Notes_Set_Up_StripeLink::set_gateway( self::get_gateway() );
15271517
WC_Payments_Notes_Set_Up_StripeLink::possibly_add_note();
1518+
1519+
require_once WCPAY_ABSPATH . 'includes/notes/class-wc-payments-notes-stripe-billing-deprecation.php';
1520+
WC_Payments_Notes_Stripe_Billing_Deprecation::possibly_add_note();
15281521
}
15291522

15301523
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '7.5', '<' ) && get_woocommerce_currency() === 'NOK' ) {
@@ -1588,6 +1581,9 @@ public static function remove_woo_admin_notes() {
15881581

15891582
require_once WCPAY_ABSPATH . 'includes/notes/class-wc-payments-notes-set-up-stripelink.php';
15901583
WC_Payments_Notes_Set_Up_StripeLink::possibly_delete_note();
1584+
1585+
require_once WCPAY_ABSPATH . 'includes/notes/class-wc-payments-notes-stripe-billing-deprecation.php';
1586+
WC_Payments_Notes_Stripe_Billing_Deprecation::possibly_delete_note();
15911587
}
15921588
}
15931589

@@ -2048,6 +2044,74 @@ public static function wcpay_show_old_woocommerce_for_hungary_sweden_and_czech_r
20482044
<?php
20492045
}
20502046

2047+
/**
2048+
* Disable the WCPay Subscriptions feature on WooPayments plugin update if it's enabled and the store is no longer eligible.
2049+
*
2050+
* @see WC_Payments_Features::is_wcpay_subscriptions_eligible() for eligibility criteria.
2051+
*/
2052+
public static function maybe_disable_wcpay_subscriptions_on_update() {
2053+
if ( WC_Payments_Features::is_wcpay_subscriptions_enabled() && ( class_exists( 'WC_Subscriptions' ) || ! WC_Payments_Features::is_wcpay_subscriptions_eligible() ) ) {
2054+
update_option( WC_Payments_Features::WCPAY_SUBSCRIPTIONS_FLAG_NAME, '0' );
2055+
}
2056+
}
2057+
2058+
/**
2059+
* Show error when WooPay opt-in is checked but no phone number was typed.
2060+
*/
2061+
public static function maybe_show_woopay_phone_number_error() {
2062+
// phpcs:ignore WordPress.Security.NonceVerification.Missing
2063+
if ( isset( $_POST['save_user_in_woopay'] ) && 'true' === $_POST['save_user_in_woopay'] ) {
2064+
// phpcs:ignore WordPress.Security.NonceVerification.Missing
2065+
if ( ! isset( $_POST['woopay_user_phone_field'] ) || ! isset( $_POST['woopay_user_phone_field']['no-country-code'] ) || empty( $_POST['woopay_user_phone_field']['no-country-code'] ) ) {
2066+
wc_add_notice( '<strong>' . __( 'Mobile Number', 'woocommerce-payments' ) . '</strong> ' . __( 'is required to create an WooPay account.', 'woocommerce-payments' ), 'error' );
2067+
}
2068+
}
2069+
}
2070+
2071+
/**
2072+
* Removes the Stripe Billing deprecation note when WooCommerce Subscriptions is installed.
2073+
*
2074+
* @param string $plugin The plugin being activated.
2075+
*/
2076+
public static function maybe_remove_stripe_billing_deprecation_note( $plugin ) {
2077+
if ( 'woocommerce-subscriptions/woocommerce-subscriptions.php' === $plugin || 'woocommerce-com-woocommerce-subscriptions/woocommerce-subscriptions.php' === $plugin ) {
2078+
require_once WCPAY_ABSPATH . 'includes/notes/class-wc-payments-notes-stripe-billing-deprecation.php';
2079+
WC_Payments_Notes_Stripe_Billing_Deprecation::possibly_delete_note();
2080+
}
2081+
}
2082+
2083+
/**
2084+
* Update the Stripe Billing deprecation note.
2085+
*/
2086+
public static function maybe_update_stripe_billing_deprecation_note() {
2087+
// If Stripe Billing is not enabled or WooCommerce Subscriptions is active, do not update the note.
2088+
if ( ! WC_Payments_Features::is_stripe_billing_enabled() || class_exists( 'WC_Subscriptions' ) ) {
2089+
return;
2090+
}
2091+
2092+
require_once WCPAY_ABSPATH . 'includes/notes/class-wc-payments-notes-stripe-billing-deprecation.php';
2093+
WC_Payments_Notes_Stripe_Billing_Deprecation::possibly_update_note();
2094+
}
2095+
2096+
/**
2097+
* Create the HTTP instantiation.
2098+
*
2099+
* @return WC_Payments_Http_Interface
2100+
*/
2101+
private static function get_wc_payments_http() {
2102+
require_once __DIR__ . '/wc-payment-api/class-wc-payments-http-interface.php';
2103+
require_once __DIR__ . '/wc-payment-api/class-wc-payments-http.php';
2104+
2105+
$http_class = apply_filters( 'wc_payments_http', null );
2106+
2107+
if ( ! $http_class instanceof WC_Payments_Http_Interface ) {
2108+
$http_class = new WC_Payments_Http( new Automattic\Jetpack\Connection\Manager( 'woocommerce-payments' ) );
2109+
$http_class->init_hooks();
2110+
}
2111+
2112+
return $http_class;
2113+
}
2114+
20512115
/**
20522116
* Determines whether we should load Stripe Billing integration classes.
20532117
*
@@ -2086,28 +2150,4 @@ private static function should_load_stripe_billing_integration() {
20862150

20872151
return (bool) ( is_countable( $result ) ? count( $result ) : 0 );
20882152
}
2089-
2090-
/**
2091-
* Disable the WCPay Subscriptions feature on WooPayments plugin update if it's enabled and the store is no longer eligible.
2092-
*
2093-
* @see WC_Payments_Features::is_wcpay_subscriptions_eligible() for eligibility criteria.
2094-
*/
2095-
public static function maybe_disable_wcpay_subscriptions_on_update() {
2096-
if ( WC_Payments_Features::is_wcpay_subscriptions_enabled() && ( class_exists( 'WC_Subscriptions' ) || ! WC_Payments_Features::is_wcpay_subscriptions_eligible() ) ) {
2097-
update_option( WC_Payments_Features::WCPAY_SUBSCRIPTIONS_FLAG_NAME, '0' );
2098-
}
2099-
}
2100-
2101-
/**
2102-
* Show error when WooPay opt-in is checked but no phone number was typed.
2103-
*/
2104-
public static function maybe_show_woopay_phone_number_error() {
2105-
// phpcs:ignore WordPress.Security.NonceVerification.Missing
2106-
if ( isset( $_POST['save_user_in_woopay'] ) && 'true' === $_POST['save_user_in_woopay'] ) {
2107-
// phpcs:ignore WordPress.Security.NonceVerification.Missing
2108-
if ( ! isset( $_POST['woopay_user_phone_field'] ) || ! isset( $_POST['woopay_user_phone_field']['no-country-code'] ) || empty( $_POST['woopay_user_phone_field']['no-country-code'] ) ) {
2109-
wc_add_notice( '<strong>' . __( 'Mobile Number', 'woocommerce-payments' ) . '</strong> ' . __( 'is required to create an WooPay account.', 'woocommerce-payments' ), 'error' );
2110-
}
2111-
}
2112-
}
21132153
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Set up Stripe Billing deprecation note for WooCommerce inbox.
4+
*
5+
* @package WooCommerce\Payments\Admin
6+
*/
7+
8+
use Automattic\WooCommerce\Admin\Notes\Note;
9+
use Automattic\WooCommerce\Admin\Notes\NoteTraits;
10+
11+
defined( 'ABSPATH' ) || exit;
12+
13+
/**
14+
* Class WC_Payments_Notes_Stripe_Billing_Deprecation
15+
*/
16+
class WC_Payments_Notes_Stripe_Billing_Deprecation {
17+
use NoteTraits {
18+
can_be_added as protected trait_can_be_added;
19+
}
20+
21+
/**
22+
* Name of the note for use in the database.
23+
*/
24+
const NOTE_NAME = 'wc-payments-notes-stripe-billing-deprecation';
25+
26+
/**
27+
* URL to the WooCommerce Subscriptions plugin page.
28+
*/
29+
const NOTE_SUBSCRIPTIONS_URL = 'https://woocommerce.com/products/woocommerce-subscriptions/';
30+
31+
/**
32+
* Checks if a note can and should be added.
33+
*
34+
* @return bool
35+
*/
36+
public static function can_be_added() {
37+
// Only show if Stripe Billing is enabled and WooCommerce Subscriptions is not installed.
38+
if ( ! self::is_bundled_subscriptions_enabled() ) {
39+
return false;
40+
}
41+
42+
// If wcpay version is >= 10.0, bail to not show the notice indefinitely.
43+
if ( version_compare( WC_Payments::get_file_version( WCPAY_PLUGIN_FILE ), '10.0.0', '>=' ) ) {
44+
return false;
45+
}
46+
47+
return self::trait_can_be_added();
48+
}
49+
50+
/**
51+
* Get the note.
52+
*/
53+
public static function get_note() {
54+
$note = new Note();
55+
$wcpay_version = WC_Payments::get_file_version( WCPAY_PLUGIN_FILE );
56+
57+
if ( version_compare( $wcpay_version, '9.7.0', '<' ) ) {
58+
$note->set_title( __( 'Important information regarding subscriptions in WooPayments', 'woocommerce-payments' ) );
59+
$note->set_content( __( 'From version 9.7 of WooPayments (scheduled for 23 July, 2025), you\'ll no longer be able to offer new product subscriptions using the built-in subscriptions functionality. To avoid disruption, please install WooCommerce Subscriptions for free.', 'woocommerce-payments' ) );
60+
} elseif ( version_compare( $wcpay_version, '9.8.0', '<' ) ) {
61+
$note->set_title( __( 'WooPayments subscriptions update', 'woocommerce-payments' ) );
62+
$note->set_content( __( 'WooPayments no longer allows customers to create new subscriptions. Beginning in version 9.8, billing for existing customer subscriptions will no longer be supported. To ensure there is no interruption of service, please install WooCommerce Subscriptions.', 'woocommerce-payments' ) );
63+
} elseif ( version_compare( $wcpay_version, '9.9.0', '<' ) ) {
64+
$note->set_title( __( 'WooPayments subscriptions update', 'woocommerce-payments' ) );
65+
$note->set_content( __( 'WooPayments no longer supports billing for existing customer subscriptions. All subscriptions data is read-only. Please install WooCommerce Subscriptions to continue managing your subscriptions.', 'woocommerce-payments' ) );
66+
} else {
67+
$note->set_title( __( 'WooPayments subscriptions update', 'woocommerce-payments' ) );
68+
$note->set_content( __( 'WooPayments no longer supports subscriptions capabilities and subscriptions data can no longer be accessed. Please install WooCommerce Subscriptions to continue managing your subscriptions.', 'woocommerce-payments' ) );
69+
}
70+
71+
$note->set_type( Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
72+
$note->set_name( self::NOTE_NAME );
73+
$note->set_source( 'woocommerce-payments' );
74+
$note->add_action( 'get-woocommerce-subscriptions', __( 'Install WooCommerce Subscriptions', 'woocommerce-payments' ), self::NOTE_SUBSCRIPTIONS_URL );
75+
76+
return $note;
77+
}
78+
79+
/**
80+
* Check if bundled subscriptions are enabled.
81+
*
82+
* @return bool
83+
*/
84+
protected static function is_bundled_subscriptions_enabled() {
85+
return WC_Payments_Features::is_stripe_billing_enabled() && ! class_exists( 'WC_Subscriptions' );
86+
}
87+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php
2+
/**
3+
* Class WC_Payments_Subscriptions_Admin_Notices
4+
*
5+
* @package WooCommerce\Payments
6+
*/
7+
8+
defined( 'ABSPATH' ) || exit;
9+
10+
/**
11+
* Class for handling admin notices related to Stripe Billing deprecation.
12+
*/
13+
class WC_Payments_Subscriptions_Admin_Notices {
14+
/**
15+
* Initializes this class's WP hooks.
16+
*
17+
* @return void
18+
*/
19+
public function init_hooks() {
20+
add_action( 'admin_notices', [ $this, 'display_stripe_billing_deprecation_notice' ] );
21+
}
22+
23+
/**
24+
* Display admin notice for Stripe Billing deprecation.
25+
*/
26+
public function display_stripe_billing_deprecation_notice() {
27+
// Only show on subscription-related pages.
28+
if ( ! $this->is_subscription_page() ) {
29+
return;
30+
}
31+
32+
// Only show if Stripe Billing is enabled and WooCommerce Subscriptions is not active.
33+
if ( ! $this->is_bundled_subscriptions_enabled() ) {
34+
return;
35+
}
36+
37+
$wcpay_version = $this->get_wcpay_version();
38+
// if wcpay version is >= 10.0, bail to not show the notice indefinitely.
39+
if ( version_compare( $wcpay_version, '10.0.0', '>=' ) ) {
40+
return;
41+
}
42+
43+
$message = '';
44+
45+
if ( version_compare( $wcpay_version, '9.7.0', '<' ) ) {
46+
$message = sprintf(
47+
/* translators: %1$s: WooCommerce Subscriptions */
48+
__( '<strong>Important:</strong> From version 9.7 of WooPayments (scheduled for 23 July, 2025), you\'ll <strong>no longer be able to offer new product subscriptions</strong>. To avoid disruption, please install <a target="_blank" href="%1$s">WooCommerce Subscriptions</a>.', 'woocommerce-payments' ),
49+
'https://woocommerce.com/products/woocommerce-subscriptions/'
50+
);
51+
} elseif ( version_compare( $wcpay_version, '9.8.0', '<' ) ) {
52+
$message = sprintf(
53+
/* translators: %1$s: WooCommerce Subscriptions */
54+
__( 'WooPayments no longer allows customers to create new subscriptions. Beginning in version 9.8, billing for existing customer subscriptions will no longer be supported. To ensure there is no interruption of service, please install <a target="_blank" href="%1$s">WooCommerce Subscriptions</a>.', 'woocommerce-payments' ),
55+
'https://woocommerce.com/products/woocommerce-subscriptions/'
56+
);
57+
} elseif ( version_compare( $wcpay_version, '9.9.0', '<' ) ) {
58+
$message = sprintf(
59+
/* translators: %1$s: WooCommerce Subscriptions */
60+
__( 'WooPayments no longer supports billing for existing customer subscriptions. All subscriptions data is read-only. Please install <a target="_blank" href="%1$s">WooCommerce Subscriptions</a> to continue managing your subscriptions.', 'woocommerce-payments' ),
61+
'https://woocommerce.com/products/woocommerce-subscriptions/'
62+
);
63+
} else {
64+
$message = sprintf(
65+
/* translators: %1$s: WooCommerce Subscriptions */
66+
__( 'WooPayments no longer supports subscriptions capabilities and subscriptions data can no longer be accessed. Please install <a target="_blank" href="%1$s">WooCommerce Subscriptions</a> to continue managing your subscriptions.', 'woocommerce-payments' ),
67+
'https://woocommerce.com/products/woocommerce-subscriptions/'
68+
);
69+
}
70+
71+
WC_Payments::display_admin_notice( $message, 'notice-warning' );
72+
}
73+
74+
/**
75+
* Check if the current page is a subscription-related page.
76+
*
77+
* @return bool
78+
*/
79+
protected function is_subscription_page() {
80+
$screen = $this->get_screen_id();
81+
82+
if ( ! $screen ) {
83+
return false;
84+
} elseif ( false !== strpos( $screen, 'edit-shop_subscription' ) ) {
85+
return true;
86+
} elseif ( false !== strpos( $screen, 'shop_subscription' ) ) {
87+
return true;
88+
} elseif ( 'woocommerce_page_wc-settings' === $screen && isset( $_GET['tab'] ) && 'subscriptions' === sanitize_text_field( wp_unslash( $_GET['tab'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
89+
return true;
90+
}
91+
92+
return false;
93+
}
94+
95+
/**
96+
* Get the current screen ID.
97+
*
98+
* @return string|false
99+
*/
100+
protected function get_screen_id() {
101+
$screen = get_current_screen();
102+
if ( ! $screen ) {
103+
return false;
104+
}
105+
106+
return $screen->id;
107+
}
108+
109+
/**
110+
* Get the WooPayments version.
111+
*
112+
* @return string
113+
*/
114+
protected function get_wcpay_version() {
115+
return WC_Payments::get_file_version( WCPAY_PLUGIN_FILE );
116+
}
117+
118+
/**
119+
* Check if bundled subscriptions are enabled.
120+
*
121+
* @return bool
122+
*/
123+
protected function is_bundled_subscriptions_enabled() {
124+
return WC_Payments_Features::is_stripe_billing_enabled() && ! class_exists( 'WC_Subscriptions' );
125+
}
126+
}

0 commit comments

Comments
 (0)