Advertisement
wpgenie

change order status to completed

Sep 29th, 2017 (edited)
589
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. /*
  2.  
  3. If you set your lotteries to be Virtual and Downloadable orders that are paid will be auto completed without this code snippet.
  4. You do not need to add file for download.
  5.  
  6. */
  7.  
  8. function custom_change_order_status( $post_id ){
  9.         global $wpdb;
  10.         $lottery_winers = get_post_meta($post_id, '_lottery_winners');
  11.  
  12.         $results = $wpdb->get_results( $wpdb->prepare( 'SELECT DISTINCT orderid FROM '.$wpdb -> prefix .'wc_lottery_log WHERE lottery_id = %d AND userid IN ('.implode(',', $lottery_winers).')', $post_id ) );
  13.         if($results){
  14.  
  15.             foreach ($results  as $result) {
  16.                 $order = new WC_Order($result->orderid );
  17.                 $order->update_status( 'completed' );
  18.             }
  19.         }
  20.  
  21.         $results = $wpdb->get_results( $wpdb->prepare( 'SELECT DISTINCT orderid FROM '.$wpdb -> prefix .'wc_lottery_log WHERE lottery_id = %d AND userid NOT IN ('.implode(',', $lottery_winers).')', $post_id ) );
  22.         if($results){
  23.  
  24.             foreach ($results  as $result) {
  25.                 $order = new WC_Order($result->orderid );
  26.                 $order->update_status( 'cancelled' );
  27.             }
  28.         }
  29. }
  30. add_action( 'wc_lottery_won' , 'custom_change_order_status');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement