Advertisement
Crecket

Untitled

Aug 3rd, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. <?php
  2. //check if an auction has been expired, send email to the winner
  3. add_action('wp_footer', 'wdm_email_auction_winner');
  4. add_action('admin_head', 'wdm_email_auction_winner');
  5.  
  6. function wdm_email_auction_winner(){
  7.  
  8. global $wpdb;
  9.  
  10. $all_auc = array(
  11. 'posts_per_page' => -1,
  12. 'post_type' => 'ultimate-auction'
  13. );
  14. if(!empty($all_auc)){
  15.  
  16. $all_auctions = get_posts( $all_auc);
  17.  
  18. foreach($all_auctions as $single_auc){
  19.  
  20. $active_term = wp_get_post_terms($single_auc->ID, 'auction-status',array("fields" => "names"));
  21. if(time() >= strtotime(get_post_meta($single_auc->ID,'wdm_listing_ends',true))){
  22. if(!in_array('expired',$active_term))
  23. {
  24. $check_tm = term_exists('expired', 'auction-status');
  25. wp_set_post_terms($single_auc->ID, $check_tm["term_id"], 'auction-status');
  26. }
  27. }
  28. }
  29. $comp_auc = array(
  30. 'posts_per_page' => -1,
  31. 'post_type' => 'ultimate-auction',
  32. 'auction-status' => 'expired'
  33. );
  34.  
  35. $completed_auctions = get_posts( $comp_auc );
  36.  
  37. //$perm_type = get_option('permalink_structure');
  38. //if(empty($perm_type))
  39. // $set_perm = "&";
  40. //else
  41. // $set_perm = "?";
  42.  
  43.  
  44. foreach($completed_auctions as $ca){
  45.  
  46. if(get_post_meta($ca->ID,'auction_email_sent',true) !== 'sent'){
  47.  
  48. $bought = get_post_meta($ca->ID,'auction_bought_status',true);
  49.  
  50. $count_qry = "SELECT COUNT(bid) FROM ".$wpdb->prefix."wdm_bidders WHERE auction_id =".$ca->ID;
  51. $count_bid = $wpdb->get_var($count_qry);
  52.  
  53. $was_sent_imd = get_post_meta($ca->ID, 'email_sent_imd', true);
  54. $is_in_progress = get_post_meta($ca->ID,'wdm_to_be_sent',true);
  55.  
  56. if($bought !== 'bought' && $count_bid > 0 && $was_sent_imd !== 'sent_imd' /*&& $is_in_progress !== 'in_progress'*/){
  57.  
  58. $reserve_price_met = get_post_meta($ca->ID, 'wdm_lowest_bid',true);
  59.  
  60. $winner_bid = "";
  61. $bid_qry = "SELECT MAX(bid) FROM ".$wpdb->prefix."wdm_bidders WHERE auction_id =".$ca->ID." ORDER BY id DESC";
  62. $winner_bid = $wpdb->get_var($bid_qry);
  63.  
  64. if($winner_bid >= $reserve_price_met){
  65. update_post_meta($ca->ID, 'wdm_to_be_sent', 'in_progress');
  66.  
  67. $winner_email = "";
  68. $email_qry = "SELECT email FROM ".$wpdb->prefix."wdm_bidders WHERE bid =".$winner_bid." AND auction_id =".$ca->ID." ORDER BY id DESC";
  69. $winner_email = $wpdb->get_var($email_qry);
  70.  
  71.  
  72. $return_url = get_post_meta($ca->ID, 'current_auction_permalink',true);
  73. wp_enqueue_script('jquery');
  74. require('ajax-actions/send-email.php');
  75. require('customscript.php');
  76. $customList = new customList();
  77. }
  78.  
  79. }
  80. }
  81. }
  82. }
  83. }
  84. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement