Advertisement
verygoodplugins

Untitled

Nov 2nd, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1. function seifsa_complete_order( $user_id, $tags ) {
  2.  
  3.     if( in_array( 'Tag Name', $tags ) ) {
  4.  
  5.         $orders = get_posts( array(
  6.             'numberposts' => 1,
  7.             'meta_key'    => '_customer_user',
  8.             'meta_value'  => $user_id,
  9.             'post_type'   => wc_get_order_types(),
  10.             'post_status' => array_keys( wc_get_order_statuses() ),
  11.             'fields'      => 'ids'
  12.         ) );
  13.  
  14.         if( ! empty( $orders ) ) {
  15.  
  16.             $order = wc_get_order( $orders[0] );
  17.             $order->update_status( 'completed' );
  18.  
  19.             wp_fusion()->user->remove_tags( array( 'Tag Name' ), $user_id );
  20.  
  21.         }
  22.  
  23.     }
  24.  
  25. }
  26.  
  27.  
  28. add_action( 'wpf_tags_modified', 'seifsa_complete_order', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement