/**
  * @param EM_Coupon $EM_Coupon
  */
 static function count_sync($EM_Coupon)
 {
     global $wpdb;
     //a bit hacky, but this is the only way at least for now
     $coupon_search = str_replace('a:1:{', '', serialize(array('coupon_code' => $EM_Coupon->coupon_code)));
     $coupon_search = substr($coupon_search, 0, strlen($coupon_search) - 1);
     $coupons_count = $wpdb->get_var('SELECT COUNT(*) FROM ' . EM_BOOKINGS_TABLE . " WHERE booking_meta LIKE '%{$coupon_search}%'");
     if ($EM_Coupon->get_count() != $coupons_count) {
         global $wpdb;
         $wpdb->update(EM_META_TABLE, array('meta_value' => $coupons_count), array('object_id' => $EM_Coupon->coupon_id, 'meta_key' => 'coupon-count'));
         return true;
     }
     return false;
 }
Example #2
0
 public static function em_booking_save($result, $EM_Booking)
 {
     if ($result && !empty($EM_Booking->booking_meta['coupon'])) {
         global $wpdb;
         $EM_Coupon = new EM_Coupon($EM_Booking->booking_meta['coupon']);
         $count = $EM_Coupon->get_count();
         if ($count) {
             //add to coupon count
             $wpdb->update(EM_META_TABLE, array('meta_value' => $count + 1), array('object_id' => $EM_Coupon->coupon_id, 'meta_key' => 'coupon-count'));
         } else {
             //start coupon count
             $wpdb->insert(EM_META_TABLE, array('meta_value' => 1, 'object_id' => $EM_Coupon->coupon_id, 'meta_key' => 'coupon-count'));
         }
     }
     return apply_filters('em_coupons_em_booking_save', $result, $EM_Booking);
 }