Skip to content

Instantly share code, notes, and snippets.

@bekarice
Created August 31, 2015 07:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bekarice/0a018cd54ce32edcb8d4 to your computer and use it in GitHub Desktop.
Save bekarice/0a018cd54ce32edcb8d4 to your computer and use it in GitHub Desktop.
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 );
@Antera
Copy link

Antera commented Oct 25, 2022

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-ajax
and get_the_ID() is empty

Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment