I’m working on a website using WooCommerce membership.
I’m using a hook called wc_memberships_user_membership_saved
, What I want is to display a recap of my order.
I read this documentation: https://docs.woocommerce.com/document/woocommerce-memberships-admin-hook-reference/#wc_memberships_user_membership_created on how to use this hook.
I want to test this hook so this is what I did in my functions.php
function gu_memberships_user_membership_saved($user_id,$user_membership_id,$is_update) {
$to = '[email protected]';
$subject = 'The subject';
$body = '<pre>' . print_r($is_update,true) . '</pre>';
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail( $to, $subject, $body, $headers );
}
add_action( 'wc_memberships_user_membership_saved', 'gu_memberships_user_membership_saved' );
I should receive a boolean: true or false. But I receive the WooCommerce membership array product instead.
Does the problem come from the params?
2
Answers
You can use it in the following way, with the
$body
variable, you can print the parameter(s) to see what it contains@type int|string $user_id user ID for the membership
@type int|string $user_membership_id post ID for the new user membership
@type bool $is_update true if the membership is being updated, false if new
The function declaration should be:
Then the
$args
will contain an array of the three variables that you are referencing, such as$args['user_id']
.