Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function maybe_cancel_subs( $user_id, $user_tags ) {
- $subscriptions = wcs_get_users_subscriptions( $user_id );
- foreach ( $subscriptions as $subscription ) {
- $product_ids = array();
- foreach ( $subscription->get_items() as $item ) {
- $product_ids[] = $item->get_product_id();
- }
- if ( in_array( 123, $product_ids ) && $subscription->get_status() == 'active' && wp_fusion()->user->has_tag( 'Cancel 123', $user_id ) ) {
- $last_order = $subscription->get_last_order();
- WC_Subscriptions_Manager::cancel_subscriptions_for_order( $last_order );
- }
- if ( in_array( 456, $product_ids ) && $subscription->get_status() == 'active' && wp_fusion()->user->has_tag( 'Cancel 456', $user_id ) ) {
- $last_order = $subscription->get_last_order();
- WC_Subscriptions_Manager::cancel_subscriptions_for_order( $last_order );
- }
- }
- }
- add_action( 'wpf_tags_modified', 'maybe_cancel_subs', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement