• Resolved martinjts

    (@martinjts)


    Hello,

    There’s currently a bug (again) where all renewal orders will receive the order number of their parent subscription. That means there will be a bunch of renewal orders with duplicate numbers. I can see from changelog that this was fixed a while back, but the problem still persists.

    I needed this solved ASAP so I fixed it myself. WooCommerce Subscriptions has a function (wcs_copy_order_meta()) that copies metadata from subscription to renewal orders and that’s the cause of this problem. I don’t know if a similar thing caused the problem in the past, but here’s what I did for the fix:

    function remove_order_numbering_wcs_order_meta( $meta, $to_order, $from_order )
    {
        $to_order_type = get_post_type( $to_order->ID );
        $from_order_type = get_post_type( $from_order->ID );
    
        if ( $to_order_type == 'shop_order' && $from_order_type == 'shop_subscription' ) {
            foreach ( $meta as $key => $value ) {
                if ( $value['meta_key'] == '_alg_wc_custom_order_number' ) {
                    unset( $meta[$key] );
                    return $meta;
                }
            }
        }
    
        return $meta;
    }
    
    add_filter( 'wcs_renewal_order_meta', 'remove_order_numbering_wcs_order_meta', 10, 3 );

    Feel free to use or refactor this code to push out an update.

Viewing 1 replies (of 1 total)
  • Plugin Support kenil802

    (@kenil802)

    Hi @martinjts,

    Thank you for sharing the code with us.

    I will surely pass your solution to the developer to implement this in future plugin updates.

    Regards,
    Kenil Shah

Viewing 1 replies (of 1 total)
  • The topic ‘Duplicate order numbers for Subscription renewals’ is closed to new replies.