Skip to content

Instantly share code, notes, and snippets.

@ucheng
Last active September 26, 2016 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ucheng/783aaf68e3c4058ad70ac57b948c235d to your computer and use it in GitHub Desktop.
Save ucheng/783aaf68e3c4058ad70ac57b948c235d to your computer and use it in GitHub Desktop.
Add Membership to Woo Customer (For WooCommerce Memberships)
<?php
//remove the following code after membership is added
add_action( 'init', 'myprefix_add_membership');
function myprefix_add_membership() {
$customers = get_users('role=customer');
$plan_id = 21356;//一般會員
foreach( $customers as $customer ):
$normal_membership = wc_memberships_get_user_membership( $customer->id, 'normal');
if ($normal_membership) {
continue;
}
$args = array(
'user_id' => $customer->id,
'plan_id' => $plan_id,
);
wc_memberships_create_user_membership( $args );
endforeach;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment