/**
  * Callback when a membership earned
  *
  * @param WC_Memberships_Membership_Plan $membership_plan membership plan
  * @param array $args
  */
 public function membership_earned($membership_plan, $args)
 {
     $prefs = $this->prefs;
     $membership_plan_slug = $this->sanitize_slug($membership_plan->get_slug());
     $user_id = $args['user_id'];
     // Check if user is excluded (required)
     if ($this->core->exclude_user($user_id) === true) {
         return;
     }
     // Award points for any membership plan
     // Make sure we award points other then zero
     if (!empty($this->prefs['any']['creds']) && !$this->prefs['any']['creds'] == 0) {
         // Check limit
         if (!$this->over_hook_limit('any', 'mycred_woocommerce_memberships', $user_id)) {
             $this->core->add_creds('mycred_woocommerce_memberships', $user_id, $prefs['any']['creds'], $prefs['any']['log'], $membership_plan->get_id(), array('ref_type' => 'wc_membership_plan'), $this->mycred_type);
         }
     }
     // Award points for specific membership plan
     // Make sure we award points other then zero
     if (!empty($this->prefs[$membership_plan_slug]['creds']) && !$this->prefs[$membership_plan_slug]['creds'] == 0) {
         // Check limit
         if (!$this->over_hook_limit($membership_plan_slug, 'mycred_woocommerce_memberships_plan_' . $membership_plan_slug, $user_id)) {
             $this->core->add_creds('mycred_woocommerce_memberships_plan_' . $membership_plan_slug, $user_id, $prefs[$membership_plan_slug]['creds'], $prefs[$membership_plan_slug]['log'], $membership_plan->get_id(), array('ref_type' => 'wc_membership_plan'), $this->mycred_type);
         }
     }
 }
 /**
  * Save related subscription data when a membership access is granted via a purchase
  *
  * Sets the end date to match subscription end date
  *
  * @since 1.0.0
  * @param WC_Memberships_Membership_Plan $plan
  * @param array $args
  */
 public function save_subscription_data(WC_Memberships_Membership_Plan $plan, $args)
 {
     $product = wc_get_product($args['product_id']);
     // Handle access from subscriptions
     if ($this->has_membership_plan_subscription($plan->get_id()) && $product->is_type(array('subscription', 'subscription_variation', 'variable-subscription'))) {
         // note: always use the product ID (not variation ID) when looking up a subscription
         // as Subs requires it
         $subscription = $this->get_order_product_subscription($args['order_id'], $product->id);
         if (!$subscription) {
             return;
         }
         if ($this->is_subscriptions_gte_2_0()) {
             // Save related subscription ID
             update_post_meta($args['user_membership_id'], '_subscription_id', $subscription->id);
         } else {
             // Save related subscription key
             $subscription_key = WC_Subscriptions_Manager::get_subscription_key($args['order_id'], $product->id);
             update_post_meta($args['user_membership_id'], '_subscription_key', $subscription_key);
         }
         // Set membership expiry date based on subscription expiry date
         if ($this->plan_grants_access_while_subscription_active($plan->get_id())) {
             $end_date = $this->is_subscriptions_gte_2_0() ? $subscription->get_date('end') ? $subscription->get_date('end') : '' : ($subscription['expiry_date'] ? $subscription['expiry_date'] : '');
             update_post_meta($args['user_membership_id'], '_end_date', $end_date);
         }
     }
 }