Created
August 31, 2015 07:11
-
-
Save bekarice/0a018cd54ce32edcb8d4 to your computer and use it in GitHub Desktop.
Dev Docs Example: WooCommerce Memberships simplified programmatic member creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Automatically grant membership to a plan at registration | |
function sv_add_membership_at_registration( $user_id ) { | |
if ( ! function_exists( 'wc_memberships' ) ) { | |
return; | |
} | |
$args = array( | |
// Enter the ID (post ID) of the plan to grant at registration | |
'plan_id' => 253, | |
'user_id' => $user_id, | |
); | |
wc_memberships_create_user_membership( $args ); | |
} | |
add_action( 'user_register', 'sv_add_membership_at_registration', 15 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, do you know how to know on which page we are in this function
sv_add_membership_at_registration()
?$_SERVER[REQUEST_URI]
is admin-ajaxand
get_the_ID()
is emptyMany thanks!