After a customer has:
- purchased a video
- rented a video
- or purchased access to a series / season
you can optionally run your own function to update the users meta data and more.
Add the following to either your themes functions.php file or within your plugin files:
add_action( 'wpvs_do_after_new_product_purchase', 'wpvs_my_custom_after_purchase_function', 10, 3 ); function wpvs_my_custom_after_purchase_function($user_id, $product_id, $purchase_type) { // YOUR CUSTOM CODE HERE }
Parameters
- user_id: The ID of the user who purchased the video
- product_id:
- The Video (POST) ID when purchase_type is purchase or rental
- The Term ID (Series / Season) when purchase_type is termpurchase
- purchase_type: Type of purchase (purchase, rental or termpurchase)
--------------------------------------------------------------------------
Do After Rental Example
The following example will automatically assign a manual (free) membership to a user after they rent a specific Video with ID 30.
add_action( 'wpvs_do_after_new_product_purchase', 'assign_manual_membership_after_rental_function', 10, 3 ); function assign_manual_membership_after_rental_function($user_id, $product_id, $purchase_type) { // adjust as needed for purchase type and Video ID (Post ID) if( $purchase_type == 'rental' && $product_id == 30 ) { // checks if Live or Test mode is active global $wpvs_memberships_live_mode; if($wpvs_memberships_live_mode == 'on') { $test_member = false; $get_memberships = 'rvs_user_memberships'; } else { $test_member = true; $get_memberships = 'rvs_user_memberships_test'; } // get user to create WPVS Customer object $member = get_user_by('id', $user_id); $wpvs_customer = new WPVS_Customer($member); // set the ID of the Membership you want to manually assign to the user $add_membership_plan_id = "Gold"; // check the customer does not already have this membership if( ! $wpvs_customer->has_membership($add_membership_plan_id) ) { // get user memberships $user_memberships = $wpvs_customer->get_memberships(); if( empty($user_memberships) ) { $user_memberships = array(); } // set when this membership access should end (never or a specific time in Timestamp format) $end_time = 'never'; // OR will expire in 3 days (remove or comment out to allow membership to never expire) $end_time = strtotime('+3 days', current_time('timestamp')); // manually added the membership $new_membership = array( 'plan' => $add_membership_plan_id, 'id' => 'wpvm-'.$add_membership_plan_id, 'amount' => '0.00', 'name' => 'Gold Access', // should match the name of the Membership 'interval' => 'none', 'ends' => $end_time, // should be 'never' or 'timestamp' 'status' => 'active', 'type' => 'manual' ); $wpvs_customer->add_membership($new_membership); wpvs_add_new_member($user_id, $test_member); } } }
Comments
0 comments
Article is closed for comments.