I'm using the Teams for WooCommerce Memberships plugin. When a user renews a Team Membership the expiry date gets extending (in this case by a year). However if an admin switches the order status (eg processing > pending > completed) the expiry date is extended twice (in the case above on processing and completed).
I've looked in the code and can see that on the standalone Memberships plugin there is some logic to stop the membership being extended if the order id has already granted an extension...
// check if user is perhaps a member, but membership is expired/cancelled
if ( wc_memberships_is_user_member( $user_id, $this->id, false )
&& ( $existing_membership = wc_memberships_get_user_membership( $user_id, $this->id ) ) ) {
$user_membership_id = $existing_membership->get_id();
$past_order_id = $existing_membership->get_order_id();
// Do not allow the same order to renew or reactivate the membership:
// this prevents admins changing order statuses from extending/reactivating the membership.
if ( ! empty( $past_order_id ) && (int) $order_id === $past_order_id ) {
I however can't see the same logic if they are purchasing a team. Is there any way that I can extend the code below to also check if the order id is the same as the previous order id?
/**
* Filters whether a team membership will be renewed.
*
* @since 1.0.0
*
* @param bool $renew whether to renew
* @param \WC_Memberships_Membership_Plan $plan the membership plan to renew team access to
* @param array $args contextual arguments
*/
$renew = apply_filters( 'wc_memberships_for_teams_renew_team_membership', (bool) $plan->get_access_length_amount(), $plan, array(
'team_id' => $team->get_id(),
'product_id' => $team->get_product_id(),
'order_id' => $item->get_order_id(),
) );
if ( $renew ) {
$this->process_team_creation_action( $item, 'renew' );
}
}
Or does anyone have any other suggestions of how to stop the team membership extending every time an order is switching between processing and complete?