Naterade
Naterade

Reputation: 2685

Woocommerce subscription hook argument only passing user id

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?

Upvotes: 1

Views: 335

Answers (1)

Josh LaBau
Josh LaBau

Reputation: 620

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 );

Upvotes: 2

Related Questions