-2

I have a WooCommerce subscription product with 2 purposes (one should never expire and one should expire). I want to enable automatic renewal for one product which is a membership product that never expires and disable automatic renewal for others. WooCommerce provides a Manual Renewal option on the settings page however it applies to all products.

I want to enable manual renewal only for a specific product so that I can use the automatic methods for others. How can I achieve this?

1 Answers1

1

I found one Woocommerce hook when subscription payment is complete, this works fine in my scenario. I compared meta between automatic and manual subscriptions got difference in _requires_manual_renewal

add_action('woocommerce_subscription_payment_complete', function($subscription){

$order_items = $subscription->get_items();

// Loop through order items
foreach ( $order_items as $item_id => $item ) {
    // To get the subscription variable product ID and simple subscription  product ID
    $product_id = $item->get_product_id();

    if($product_id  == 295 ){
        
        update_post_meta($subscription->id,'_requires_manual_renewal',false);
    }
    else{
        
    update_post_meta($subscription->id,'_requires_manual_renewal',true);
    }
}
},10,2);