Last active
September 26, 2016 15:07
-
-
Save ucheng/783aaf68e3c4058ad70ac57b948c235d to your computer and use it in GitHub Desktop.
Add Membership to Woo Customer (For WooCommerce Memberships)
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 | |
//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