mirror of
https://github.com/pronamic/woocommerce-subscriptions.git
synced 2025-10-17 14:52:56 +00:00
2.0.18
This commit is contained in:
@@ -165,6 +165,8 @@ function wcs_get_subscriptions_for_resubscribe_order( $order ) {
|
||||
* 3. its parent order must not have already been superseded by a new order (to prevent
|
||||
* displaying "Resubscribe" links on subscriptions that have already been renewed)
|
||||
* 4. the products to which the subscription relates must not have been deleted
|
||||
* 5. have a recurring amount greater than $0, to avoid allowing resubscribes to subscriptions
|
||||
* where the entire cost is charged in a sign-up fee
|
||||
*
|
||||
* @param int | WC_Subscription $subscription Post ID of a 'shop_subscription' post, or instance of a WC_Subscription object
|
||||
* @param int The ID of a user
|
||||
@@ -189,6 +191,14 @@ function wcs_can_user_resubscribe_to( $subscription, $user_id = '' ) {
|
||||
|
||||
$can_user_resubscribe = false;
|
||||
|
||||
} elseif ( ! $subscription->has_status( array( 'cancelled', 'expired', 'trash' ) ) ) {
|
||||
|
||||
$can_user_resubscribe = false;
|
||||
|
||||
} elseif ( $subscription->get_total() <= 0 ) {
|
||||
|
||||
$can_user_resubscribe = false;
|
||||
|
||||
} else {
|
||||
|
||||
$resubscribe_orders = get_posts( array(
|
||||
@@ -207,6 +217,9 @@ function wcs_can_user_resubscribe_to( $subscription, $user_id = '' ) {
|
||||
// Make sure all line items still exist
|
||||
$all_line_items_exist = true;
|
||||
|
||||
// Check if product in subscription is limited
|
||||
$has_active_limited_subscription = false;
|
||||
|
||||
foreach ( $subscription->get_items() as $line_item ) {
|
||||
|
||||
$product = ( ! empty( $line_item['variation_id'] ) ) ? wc_get_product( $line_item['variation_id'] ) : wc_get_product( $line_item['product_id'] );
|
||||
@@ -215,9 +228,14 @@ function wcs_can_user_resubscribe_to( $subscription, $user_id = '' ) {
|
||||
$all_line_items_exist = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( 'active' == $product->limit_subscriptions && ( wcs_user_has_subscription( $user_id, $product->id, 'on-hold' ) || wcs_user_has_subscription( $user_id, $product->id, 'active' ) ) ) {
|
||||
$has_active_limited_subscription = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $resubscribe_orders ) && $subscription->get_completed_payment_count() > 0 && $subscription->get_total() > 0 && true === $all_line_items_exist && $subscription->has_status( array( 'cancelled', 'expired', 'trash' ) ) ) {
|
||||
if ( empty( $resubscribe_orders ) && $subscription->get_completed_payment_count() > 0 && true === $all_line_items_exist && false === $has_active_limited_subscription ) {
|
||||
$can_user_resubscribe = true;
|
||||
} else {
|
||||
$can_user_resubscribe = false;
|
||||
|
Reference in New Issue
Block a user