WooCommerce subscription webhoook payload empty
I had the same problem, but finally I understood how to do : the $subscription object serialize only the public members of the WC_subscrition object, so if you want to use the private field you must use the getter. In example, if you need the trial period expiration day from the woocommerce_subscription_payment_complete action, this is the way:
function fn_woocommerce_subscription_payment_complete ($subscription){ 'subscription_trial_end' => $subscription->get_date( 'trial_end' ); //do whatever you want}add_action( 'woocommerce_subscription_payment_complete', 'fn_woocommerce_subscription_payment_complete', 10, 1 );
Last tip, keep attention on the number of arguments passed from action ( last parameter in add_action() )
To add to Mauro's answer, indeed only public variables in WC_Subscription
object are serialized. I was able to include the id (or any other property) in the webhook payload by creating a new temporary public variable inside the WC_Subscription Class using the following code:
function fn_woocommerce_subscription_payment_complete ($subscription){ $subscription->my_id=$subscription->get_id(); }add_action( 'woocommerce_subscription_renewal_payment_complete', 'fn_woocommerce_subscription_payment_complete', 10, 1 );