Created
August 18, 2018 09:49
-
-
Save ucheng/b9b4a80e6b5a9fef0078f4ac30431060 to your computer and use it in GitHub Desktop.
bulk add user to subscription
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 | |
function oneday_bulk_add_user_to_subscription() { | |
$args= array( | |
array( 'role' => 'Subscriber' ) | |
); | |
// The Query | |
$user_query = new WP_User_Query( $args ); | |
// User Loop | |
if ( ! empty( $user_query->get_results() ) ) { | |
foreach ( $user_query->get_results() as $user ) { | |
$rcp_args = array( | |
'subscription_id' => 1 | |
'status' => 'active', | |
// 'expiration' => date( 'Y-m-d 23:59:59', strtotime( '+1 month', current_time( 'timestamp' ) ) ), | |
// 'discount_code' => 'free_subscription' | |
); | |
rcp_add_user_to_subscription( $user->ID, $rcp_args ); | |
} | |
} else { | |
// echo 'No users found.'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment