From f4ea054ad7971eff11c9027c0e42acd2b519d262 Mon Sep 17 00:00:00 2001 From: maximilianoRicoTabo Date: Mon, 13 May 2024 15:37:37 -0300 Subject: [PATCH 1/2] Edit customer in Stripe button is present in Edit Member page despite the active subscription belongs to a different gateway. * Check if there's an active Stripe subscription before render the button --- .../pmpro-class-member-edit-panel-subscriptions.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/adminpages/member-edit/pmpro-class-member-edit-panel-subscriptions.php b/adminpages/member-edit/pmpro-class-member-edit-panel-subscriptions.php index b95c6a9af4..41d01d1237 100644 --- a/adminpages/member-edit/pmpro-class-member-edit-panel-subscriptions.php +++ b/adminpages/member-edit/pmpro-class-member-edit-panel-subscriptions.php @@ -12,10 +12,13 @@ public function __construct() { $user = self::get_user(); $stripe = new PMProGateway_Stripe(); $customer = $stripe->get_customer_for_user( $user->ID ); - + $subscriptions = PMPro_Subscription::get_subscriptions_for_user( $user->ID ); + $user_has_active_stripe_subscription = array_reduce( $subscriptions, function ( $carry, $subscription ) { + return $carry || ( $subscription->get_status() === 'active' && $subscription->get_gateway() === 'stripe' ); + }, false ); // Link to the Stripe Customer if they have one. // TODO: Eventually make this a hook or filter so other gateways can add their own links. - if ( ! empty( $customer ) ) { + if ( ! empty( $customer ) && $user_has_active_stripe_subscription ) { $this->title_link = '' . esc_html__( 'Edit customer in Stripe', 'paid-memberships-pro' ) . ''; } } From a95a580779fa0362f17733b06f9e89c6a7f52fc3 Mon Sep 17 00:00:00 2001 From: David Parker Date: Mon, 17 Jun 2024 11:09:04 -0400 Subject: [PATCH 2/2] Changing locations of Stripe Customer links --- ...o-class-member-edit-panel-subscriptions.php | 14 -------------- ...pmpro-class-member-edit-panel-user-info.php | 7 +++++++ adminpages/subscriptions.php | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/adminpages/member-edit/pmpro-class-member-edit-panel-subscriptions.php b/adminpages/member-edit/pmpro-class-member-edit-panel-subscriptions.php index 41d01d1237..6dbd902a27 100644 --- a/adminpages/member-edit/pmpro-class-member-edit-panel-subscriptions.php +++ b/adminpages/member-edit/pmpro-class-member-edit-panel-subscriptions.php @@ -7,20 +7,6 @@ class PMPro_Member_Edit_Panel_Subscriptions extends PMPro_Member_Edit_Panel { public function __construct() { $this->slug = 'subscriptions'; $this->title = __( 'Subscriptions', 'paid-memberships-pro' ); - - // Get the user's Stripe Customer if they have one. - $user = self::get_user(); - $stripe = new PMProGateway_Stripe(); - $customer = $stripe->get_customer_for_user( $user->ID ); - $subscriptions = PMPro_Subscription::get_subscriptions_for_user( $user->ID ); - $user_has_active_stripe_subscription = array_reduce( $subscriptions, function ( $carry, $subscription ) { - return $carry || ( $subscription->get_status() === 'active' && $subscription->get_gateway() === 'stripe' ); - }, false ); - // Link to the Stripe Customer if they have one. - // TODO: Eventually make this a hook or filter so other gateways can add their own links. - if ( ! empty( $customer ) && $user_has_active_stripe_subscription ) { - $this->title_link = '' . esc_html__( 'Edit customer in Stripe', 'paid-memberships-pro' ) . ''; - } } /** diff --git a/adminpages/member-edit/pmpro-class-member-edit-panel-user-info.php b/adminpages/member-edit/pmpro-class-member-edit-panel-user-info.php index e277973250..6896f184b0 100644 --- a/adminpages/member-edit/pmpro-class-member-edit-panel-user-info.php +++ b/adminpages/member-edit/pmpro-class-member-edit-panel-user-info.php @@ -11,6 +11,13 @@ public function __construct() { $this->title_link = empty( $user->ID ) ? '' : '' . esc_html__( 'Edit User', 'paid-memberships-pro' ) . ''; $this->submit_text = empty( $user->ID ) ? __( 'Create User ') : __( 'Update User Info', 'paid-memberships-pro' ); + // If this user has an associated Stripe Customer, add a link to edit that Stripe Customer as well. + $stripe = new PMProGateway_Stripe(); + $customer = $stripe->get_customer_for_user( $user->ID ); + if ( ! empty( $customer ) ) { + $this->title_link .= '' . esc_html__( 'Edit Customer in Stripe', 'paid-memberships-pro' ) . ''; + } + // Show user updated or user created message if necessary. if ( isset( $_REQUEST['user_id'] ) && ! empty( $_REQUEST['user_id'] && ! empty( $_REQUEST['user_info_action'] ) ) ) { if ( 'updated' === $_REQUEST['user_info_action'] ) { diff --git a/adminpages/subscriptions.php b/adminpages/subscriptions.php index 0ad2ff7666..fc3ff88a43 100644 --- a/adminpages/subscriptions.php +++ b/adminpages/subscriptions.php @@ -71,6 +71,24 @@ class="page-title-action pmpro-has-icon pmpro-has-icon-no" + get_gateway() ) { + $stripe = new PMProGateway_Stripe(); + $customer = $stripe->get_customer_for_user( $sub_user->ID ); + if ( ! empty( $customer ) ) { + ?> + + + + +