Advertisement
verygoodplugins

Untitled

Sep 4th, 2019
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. function maybe_cancel_subs( $user_id, $user_tags ) {
  2.  
  3.     $subscriptions = wcs_get_users_subscriptions( $user_id );
  4.  
  5.     foreach ( $subscriptions as $subscription ) {
  6.  
  7.         $product_ids = array();
  8.  
  9.         foreach ( $subscription->get_items() as $item ) {
  10.  
  11.             $product_ids[] = $item->get_product_id();
  12.  
  13.         }
  14.  
  15.         if ( in_array( 123, $product_ids ) && $subscription->get_status() == 'active' && wp_fusion()->user->has_tag( 'Cancel 123', $user_id ) ) {
  16.  
  17.             $last_order = $subscription->get_last_order();
  18.             WC_Subscriptions_Manager::cancel_subscriptions_for_order( $last_order );
  19.  
  20.         }
  21.  
  22.         if ( in_array( 456, $product_ids ) && $subscription->get_status() == 'active' && wp_fusion()->user->has_tag( 'Cancel 456', $user_id ) ) {
  23.  
  24.             $last_order = $subscription->get_last_order();
  25.             WC_Subscriptions_Manager::cancel_subscriptions_for_order( $last_order );
  26.  
  27.         }
  28.  
  29.     }
  30.  
  31. }
  32.  
  33. add_action( 'wpf_tags_modified', 'maybe_cancel_subs', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement