verygoodplugins

Untitled

Feb 1st, 2021 (edited)
307
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function ffp_sync_expiration_date( $membership, $args ) {
  2.  
  3.     $user_membership = wc_memberships_get_user_membership( $args['user_membership_id'] );
  4.  
  5.     ////////// FFP Adding code to add Expiration date & Status as custom user field in AC for each membership
  6.    
  7.     $ffp_plan_id = $user_membership->plan_id;
  8.  
  9.     ////////// Vet membership Start
  10.    
  11.     if ( $ffp_plan_id == 917 ) {
  12.  
  13.         $ffp_status = $user_membership->get_status();
  14.  
  15.         $ffp_update_data = array(
  16.             'membership_status_vet' => $ffp_status,
  17.         );
  18.  
  19.         if( ! empty( $user_membership->get_end_date() ) ) {
  20.             $ffp_update_data['membership_expiration_vet'] = $user_membership->get_end_date();
  21.         }
  22.        
  23.         wp_fusion()->user->push_user_meta( $args['user_id'], $ffp_update_data );
  24.     }
  25.     ////////// Vet membership End
  26.     ///
  27.     ////////// Student membership Start
  28.    
  29.     if ( $ffp_plan_id == 2264775 ) {
  30.  
  31.         $ffp_status = $user_membership->get_status();
  32.  
  33.         $ffp_update_data = array(
  34.             'membership_status_student' => $ffp_status,
  35.         );
  36.  
  37.         if( ! empty( $user_membership->get_end_date() ) ) {
  38.             $ffp_update_data['membership_expiration_student'] = $user_membership->get_end_date();
  39.         }
  40.        
  41.         wp_fusion()->user->push_user_meta( $args['user_id'], $ffp_update_data );
  42.     }
  43.     ////////// Student membership End
  44.     ///
  45.     ////////// Trainer membership Start
  46.    
  47.  
  48.     if ( $ffp_plan_id == 188504 ) {
  49.  
  50.         $ffp_status = $user_membership->get_status();
  51.  
  52.         $ffp_update_data = array(
  53.             'membership_status_trainer' => $ffp_status,
  54.         );
  55.  
  56.         if( ! empty( $user_membership->get_end_date() ) ) {
  57.             $ffp_update_data['membership_expiration_trainer'] = $user_membership->get_end_date();
  58.         }
  59.        
  60.         wp_fusion()->user->push_user_meta( $args['user_id'], $ffp_update_data );
  61.     }
  62.     ////////// Trainer membership End
  63.     ///
  64.     ////////// Groomer membership Start
  65.    
  66.  
  67.     if ( $ffp_plan_id == 1012216 ) {
  68.  
  69.         $ffp_status = $user_membership->get_status();
  70.  
  71.         $ffp_update_data = array(
  72.             'membership_status_groomer' => $ffp_status,
  73.         );
  74.  
  75.         if( ! empty( $user_membership->get_end_date() ) ) {
  76.             $ffp_update_data['membership_expiration_groomer'] = $user_membership->get_end_date();
  77.         }
  78.        
  79.         wp_fusion()->user->push_user_meta( $args['user_id'], $ffp_update_data );
  80.     }
  81.     ////////// Groomer membership End
  82.     ///
  83.     ////////// CP Registered membership Start
  84.    
  85.  
  86.     if ( $ffp_plan_id == 2549808 ) {
  87.  
  88.         $ffp_status = $user_membership->get_status();
  89.  
  90.         $ffp_update_data = array(
  91.             'membership_status_cpregistered' => $ffp_status,
  92.         );
  93.  
  94.         if( ! empty( $user_membership->get_end_date() ) ) {
  95.             $ffp_update_data['membership_expiration_cpregistered'] = $user_membership->get_end_date();
  96.         }
  97.        
  98.         wp_fusion()->user->push_user_meta( $args['user_id'], $ffp_update_data );
  99.     }
  100.     ////////// CP Registered membership End
  101.     ///
  102.     ////////// CP Leader membership Start
  103.    
  104.  
  105.     if ( $ffp_plan_id == 326174 ) {
  106.  
  107.         $ffp_status = $user_membership->get_status();
  108.  
  109.         $ffp_update_data = array(
  110.             'membership_status_cpleader' => $ffp_status,
  111.         );
  112.  
  113.         if( ! empty( $user_membership->get_end_date() ) ) {
  114.             $ffp_update_data['membership_expiration_cpleader'] = $user_membership->get_end_date();
  115.         }
  116.        
  117.         wp_fusion()->user->push_user_meta( $args['user_id'], $ffp_update_data );
  118.     }
  119.     ////////// CP Leader membership End
  120.     ///
  121.     ////////// Certified Practice membership Start
  122.    
  123.  
  124.     if ( $ffp_plan_id == 326153 ) {
  125.  
  126.         $ffp_status = $user_membership->get_status();
  127.  
  128.         $ffp_update_data = array(
  129.             'membership_status_cpmember' => $ffp_status,
  130.         );
  131.  
  132.         if( ! empty( $user_membership->get_end_date() ) ) {
  133.             $ffp_update_data['membership_expiration_cpmember'] = $user_membership->get_end_date();
  134.         }
  135.        
  136.         wp_fusion()->user->push_user_meta( $args['user_id'], $ffp_update_data );
  137.     }
  138.     ////////// Certified Practice membership End
  139.  
  140.     //////// FFP End Added code to add Expiration date & Status as custom user field in AC for each membership
  141.  
  142.     if( ! empty( $user_membership->get_end_date() ) ) {
  143.         wp_fusion()->user->push_user_meta( $args['user_id'], array( 'membership_expiration' => $user_membership->get_end_date() ) );
  144.     }
  145. }
  146. add_action( 'wc_memberships_grant_membership_access_from_purchase', 'ffp_sync_expiration_date', 20, 2 );
RAW Paste Data