Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Dev Docs Example: WooCommerce Memberships simplified programmatic member creation
<?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