0

I am creating a function that will be hooked into the woocommerce_subscription_payment_complete action.

That action emits 1 parameter ($subscription) which is an object representing the subscription that has just received a payment.

How do I access the value of $subscription from within my function?

0

If you look at the documentation for add_action, you see that it accepts 4 parameters. The first 2 are required for adding any actions. If you want to change the priority of your action, you use the third parameter. If you want to change the number of arguments the function accepts, you use the fourth parameter.

For your example, the number of arguments is 1, so we use 1 as the fourth parameter. We still need the the third parameter though, so we use the default value of 10.

add_action( 'woocommerce_subscription_payment_complete', 'wpse_106269_payment_complete', 10, 1 );
function wpse_106269_payment_complete( $subscription ) {
  //* Use $subscription
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.