Advertisement
verygoodplugins

Untitled

Dec 19th, 2018
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. function wpf_subscription_status_hold( $subscription, $status, $old_status ) {
  2.  
  3.     $user_id = $subscription->get_user_id();
  4.  
  5.     foreach ( $subscription->get_items() as $line_item ) {
  6.  
  7.         $product_id = $line_item->get_product_id();
  8.  
  9.         $settings = get_post_meta( $product_id, 'wpf-settings-woo', true );
  10.  
  11.         if ( ! empty( $settings ) ) {
  12.  
  13.             if( $status == 'on-hold' && ! empty( $settings['apply_tags_hold'] ) ) {
  14.  
  15.                 wp_clear_scheduled_hook( 'wpf_subscription_status_hold', array( $subscription, $settings ) );
  16.  
  17.                 wp_fusion()->logger->handle( 'info', $user_id, 'WooCommerce subscription <a href="' . admin_url( "post.php?post=" . $subscription->get_id() . "&action=edit") . '" target="_blank">#' . $subscription->get_id() . '</a> status changed to <strong>on-hold</strong>', array( 'source' => 'wc-subscriptions' ) );
  18.  
  19.                 $user_id = $subscription->get_user_id();
  20.  
  21.                 if( ! empty( $settings['apply_tags_hold'] ) ) {
  22.                     wp_fusion()->user->apply_tags( $settings['apply_tags_hold'], $user_id );
  23.                 }
  24.  
  25.                 if( ! empty( $settings['remove_tags'] ) ) {;
  26.                     wp_fusion()->user->remove_tags( $settings['apply_tags'], $user_id );
  27.                 }
  28.  
  29.             }
  30.  
  31.         }
  32.  
  33.     }
  34. }
  35.  
  36. add_action( 'woocommerce_subscription_status_updated', 'wpf_subscription_status_hold', 20, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement