Change order status when using COD payment with WooCommerce Subscriptions

Change order status when using COD payment with WooCommerce Subscriptions renewals on child sites.

Snippet Type

Execute on Child Sites

Snippet

add_filter( 'wcs_new_order_created', 'customize_renewal_cod_order_status', 10, 3 );
function customize_renewal_cod_order_status( $order, $subscription, $type ) {
    $parent_order = $subscription->get_related_orders('all', 'parent');
    $parent_order = reset($parent_order);

    if ( $type === 'renewal_order' && $parent_order->get_payment_method() === 'cod' && $order->has_status('on-hold') ) {
        $order->set_status('wc-processing');
        $order->save();

        $subscription->set_status('wc-active'); // Optional
        $subscription->save(); // Optional
    }
    return $order;
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.