woocommerce订阅切换操作不起作用

Based on the information in woocommerce documentation: https://docs.woocommerce.com/document/subscriptions/develop/action-reference/
The action: woocommerce_subscription_status_changed,
Should be triggered also when the subscription upgraded or downgraded - switched,
But it only works on the following situations:
active, on-hold, cancelled
Here is my sample code:

add_action('woocommerce_subscription_status_changed', 'test', 10, 3);
function test( $subscription_id, $old_status, $new_status ) {
    global $woocommerce;
    $file_content = $subscription_id.' '.$old_status.' '.$new_status;
    $filename = '/tmp/test_file.txt';
    file_put_contents($filename, $file_content);
}


The code above works, but not when the subscription switched, my question is why ?

You should use woocommerce_subscriptions_switch_completed action istead for this purpose

The hook you are using

     add_action('woocommerce_subscription_status_changed', 'test', 10, 3);  <== 2.0 or earlier

has become obsolete and only works in woocommerce subscription 2.0 or below. 2.0+ and above uses the following hook.

 add_action( 'woocommerce_subscription_status_updated', 'test', 1, 3); <=== after 2.0

 function test( $subscription_id, $old_status, $new_status ) {
     $file_content = $subscription_id.' '.$old_status.' '.$new_status;
     $filename = '/tmp/test_file.txt';
     file_put_contents($filename, $file_content);
   }

You can remove the global $woocommerce, as it is not longer necessary.