• Viktor123b

    (@viktorbengtsson8)


    With WooCommerce Subscriptions I want when you renew an order and subscription with cash on delivery (cod) the subscription status should change to on-hold until order is completed. Before a renew subscription order is paid, its status is ‘pending’ and when paid ‘processed’

    The current code I have on ‘woocommerce_thankyou’ only works on new subscriptions but not on renewed ones. I have tried ‘woocommerce_order_status_changed’ as seen below, but does not work.

    
    add_action( 'woocommerce_order_status_changed', 'change_order_status_conditionally', 10, 4 );
    function change_order_status_conditionally( $order_id, $status_from, $status_to, $order ) {
        if( $order->get_payment_method() === 'stripe' ) {
          $order->update_status( 'completed' );
        } else if($order->get_payment_method() === 'cod' && $status_to === 'processing') {
          if( wcs_order_contains_subscription( $order )) {
            // Get an array of WC_Subscription objects
            $subscriptions = wcs_get_subscriptions_for_order( $order_id );
            foreach( $subscriptions as $subscription_id => $subscription ){
                // Change the status of the WC_Subscription object
                $subscription->update_status( 'on-hold' );
            }
          }
        }
    }
    
    • This topic was modified 5 years, 4 months ago by Jan Dembowski.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Setting WooCommerce Subscription status on renewal based on payment method’ is closed to new replies.