示例#1
0
/**
 * Approve a resume
 * @param  int $job_id
 * @param  int $user_id
 * @param  int $user_package_id
 */
function wc_paid_listings_approve_resume_with_package($resume_id, $user_id, $user_package_id)
{
    // Update status
    $update_resume = array();
    $update_resume['ID'] = $resume_id;
    $update_resume['post_status'] = get_option('resume_manager_submission_requires_approval') ? 'pending' : 'publish';
    $update_resume['post_date'] = current_time('mysql');
    $update_resume['post_date_gmt'] = current_time('mysql', 1);
    wp_update_post($update_resume);
    update_post_meta($resume_id, '_user_package_id', $user_package_id);
    // Count job
    wc_paid_listings_increase_package_count($user_id, $user_package_id);
}
示例#2
0
/**
 * @deprecated
 */
function increase_job_package_job_count($user_id, $package_id)
{
    wc_paid_listings_increase_package_count($user_id, $package_id);
}
 /**
  * When switching a subscription we need to update old listings.
  *
  * No need to give the user a new package; thats still handled by the orders class.
  */
 public function switched_subscription($user_id, $original_subscription_key, $new_subscription_key)
 {
     global $wpdb;
     // Get subscription details
     $old_subscription = WC_Subscriptions_Manager::get_subscription($original_subscription_key);
     $old_subscription_type = get_post_meta($old_subscription['product_id'], '_package_subscription_type', true);
     $old_subscription_type = empty($old_subscription_type) ? 'package' : $old_subscription_type;
     $new_subscription = WC_Subscriptions_Manager::get_subscription($new_subscription_key);
     $new_subscription_type = get_post_meta($new_subscription['product_id'], '_package_subscription_type', true);
     $new_subscription_type = empty($new_subscription_type) ? 'package' : $new_subscription_type;
     // Get the user package
     $user_package = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wcpl_user_packages WHERE user_id = %d AND order_id = %d AND product_id = %d;", $user_id, $old_subscription['order_id'], $old_subscription['product_id']));
     if ($user_package) {
         $switching_to_package = wc_get_product($new_subscription['product_id']);
         // If invalid, abort
         if (!$switching_to_package->is_type(array('job_package', 'resume_package', 'job_package_subscription', 'resume_package_subscription'))) {
             return false;
         }
         $switching_to_package_id = wc_paid_listings_give_user_package($user_id, $new_subscription['product_id'], $new_subscription['order_id']);
         // Ensure package is not given twice
         update_post_meta($new_subscription['order_id'], 'wc_paid_listings_packages_processed', true);
         // Upgrade?
         $upgrading = $switching_to_package->get_limit() >= $user_package->package_limit;
         // Delete the old package
         $wpdb->delete("{$wpdb->prefix}wcpl_user_packages", array('id' => $user_package->id));
         // Update old listings
         if ('listing' === $new_subscription_type && $switching_to_package_id) {
             $listing_ids = $wpdb->get_col($wpdb->prepare("\n\t\t\t\t\tSELECT post_id FROM {$wpdb->postmeta}\n\t\t\t\t\tLEFT JOIN {$wpdb->posts} ON {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID\n\t\t\t\t\tWHERE meta_key = '_user_package_id'\n\t\t\t\t\tAND meta_value = %s;\n\t\t\t\t", $user_package->id));
             foreach ($listing_ids as $listing_id) {
                 // If we are not upgrading, expire the old listing
                 if (!$upgrading) {
                     $listing = array('ID' => $listing_id, 'post_status' => 'expired');
                     wp_update_post($listing);
                 } else {
                     wc_paid_listings_increase_package_count($user_id, $switching_to_package_id);
                     // Change the user package ID and package ID
                     update_post_meta($listing_id, '_user_package_id', $switching_to_package_id);
                     update_post_meta($listing_id, '_package_id', $new_subscription['product_id']);
                 }
                 // Featured or not
                 update_post_meta($listing_id, '_featured', $switching_to_package->is_featured() ? 1 : 0);
                 // Fire action
                 do_action('wc_paid_listings_switched_subscription', $listing_id, $user_package);
             }
         }
     }
 }