Exemple #1
0
/**
 * @deprecated
 */
function get_user_job_package($package_id)
{
    return wc_paid_listings_get_user_package($package_id);
}
 /**
  * Purchase a job package
  * @param  int|string $package_id
  * @param  int $job_id
  * @return bool Did it work or not?
  */
 private static function process_package($package_id, $is_user_package, $job_id)
 {
     if ($is_user_package) {
         $user_package = wc_paid_listings_get_user_package($package_id);
         $package = wc_get_product($user_package->get_product_id());
         // Give job the package attributes
         update_post_meta($job_id, '_job_duration', $user_package->get_duration());
         update_post_meta($job_id, '_featured', $user_package->is_featured() ? 1 : 0);
         update_post_meta($job_id, '_package_id', $user_package->get_product_id());
         update_post_meta($job_id, '_user_package_id', $package_id);
         if ($package && 'listing' === $package->package_subscription_type) {
             update_post_meta($job_id, '_job_expires', '');
             // Never expire automatically
         }
         // Approve the job
         if (in_array(get_post_status($job_id), array('pending_payment', 'expired'))) {
             wc_paid_listings_approve_job_listing_with_package($job_id, get_current_user_id(), $package_id);
         }
         do_action('wcpl_process_package_for_job_listing', $package_id, $is_user_package, $job_id);
         return true;
     } elseif ($package_id) {
         $package = wc_get_product($package_id);
         // Give job the package attributes
         update_post_meta($job_id, '_job_duration', $package->get_duration());
         update_post_meta($job_id, '_featured', $package->is_featured() ? 1 : 0);
         update_post_meta($job_id, '_package_id', $package_id);
         if ('listing' === $package->package_subscription_type) {
             update_post_meta($job_id, '_job_expires', '');
             // Never expire automatically
         }
         // Add package to the cart
         WC()->cart->add_to_cart($package_id, 1, '', '', array('job_id' => $job_id));
         woocommerce_add_to_cart_message($package_id);
         // Clear cookie
         wc_setcookie('chosen_package_id', '', time() - HOUR_IN_SECONDS);
         wc_setcookie('chosen_package_is_user_package', '', time() - HOUR_IN_SECONDS);
         do_action('wcpl_process_package_for_job_listing', $package_id, $is_user_package, $job_id);
         // Redirect to checkout page
         wp_redirect(get_permalink(woocommerce_get_page_id('checkout')));
         exit;
     }
 }