Woocommerce subscription hook argument only passing user id

334 Views Asked by At

I'm tapping into the subscription action hook scheduled_subscription_payment.

function subscription_renewal($arg) {
    echo, '<pre>' print_r($arg, true);
}
add_action( 'scheduled_subscription_payment', 'subscription_renewal' );

Its only returning the user id of the subscriber and I've also tried multiple arguments. I want all the order (subscription) information but cannot find another method to do so. Does this method pass anything but the user id or is there another method?

1

There are 1 best solutions below

0
On BEST ANSWER

This action does pass in two parameters, user_id and the subscription_key. You need to specify that the function takes two arguments, and you need to also specify that your action processes two arguments:

// Indicate two parameters in function definition
function subscription_renewal($user_id, $subscription_key) {
  //Logic goes here
}

// Indicate that the action has priority 10 and takes two parameters
add_action( 'scheduled_subscription_payment', 'subscription_renewal', 10, 2 );