$postvals['cp_sys_userIP'] = appthemes_get_ip(); $postvals['user_id'] = $current_user->ID; $ad_pack_id = isset($_POST['ad_pack_id']) ? appthemes_numbers_only($_POST['ad_pack_id']) : false; if ($ad_pack_id) { $postvals['pack_duration'] = cp_get_ad_pack_length($ad_pack_id); } $coupon = false; if (cp_payments_is_enabled()) { // see if the featured ad checkbox has been checked if (isset($_POST['featured_ad'])) { $postvals['featured_ad'] = $_POST['featured_ad']; // get the featured ad price into the array $postvals['cp_sys_feat_price'] = $cp_options->sys_feat_price; } // calculate the ad listing fee and put into a variable $postvals['cp_sys_ad_listing_fee'] = cp_ad_listing_fee($_POST['cat'], $ad_pack_id, $postvals['cp_price'], $price_curr); // calculate the total cost of the ad if (isset($postvals['cp_sys_feat_price'])) { $postvals['cp_sys_total_ad_cost'] = cp_calc_ad_cost($_POST['cat'], $ad_pack_id, $postvals['cp_sys_feat_price'], $postvals['cp_price'], $coupon, $price_curr); } else { $postvals['cp_sys_total_ad_cost'] = cp_calc_ad_cost($_POST['cat'], $ad_pack_id, 0, $postvals['cp_price'], $coupon, $price_curr); } //UPDATE TOTAL BASED ON MEMBERSHIP //check for current users active membership pack and that its not expired if (!empty($current_user->active_membership_pack) && appthemes_days_between_dates($current_user->membership_expires) > 0) { $postvals['membership_pack'] = get_pack($current_user->active_membership_pack); //update the total cost based on the membership pack ID and current total cost $postvals['cp_sys_total_ad_cost'] = get_pack_benefit($postvals['membership_pack'], $postvals['cp_sys_total_ad_cost']); //add featured cost to static pack type if (isset($postvals['cp_sys_feat_price']) && in_array($postvals['membership_pack']->pack_type, array('required_static', 'static'))) { $postvals['cp_sys_total_ad_cost'] += $postvals['cp_sys_feat_price'];
function cp_calc_ad_cost($catid, $ad_pack_id, $featuredprice, $cp_price, $cp_coupon, $price_curr) { $adlistingfee = ''; $totalcost_out = ''; // if we're charging for ads calculate the price if (get_option('cp_charge_ads') == 'yes') { $adlistingfee = cp_ad_listing_fee($catid, $ad_pack_id, $cp_price, $price_curr); } // calculate the total cost for the ad. $totalcost_out = $adlistingfee + $featuredprice; //discount for coupon amount if its set if (isset($cp_coupon->coupon_discount) && isset($cp_coupon->coupon_discount_type)) { if ($cp_coupon->coupon_discount_type != '%') { $totalcost_out = $totalcost_out - (double) $cp_coupon->coupon_discount; } else { $totalcost_out = $totalcost_out - $totalcost_out * ((double) $cp_coupon->coupon_discount / 100); } } //set proper return format $totalcost_out = number_format($totalcost_out, 2, '.', ''); //if total cost is less then zero, then make the cost zero (free) if ($totalcost_out < 0) { $totalcost_out = 0; } return $totalcost_out; }
/** * Calculates the total ad cost. * * @param int $category_id * @param int $package_id * @param float $featuredprice * @param float $cp_price * @param string $cp_coupon (deprecated) * @param string $price_curr * * @return float */ function cp_calc_ad_cost($category_id, $package_id, $featuredprice, $cp_price, $cp_coupon, $price_curr) { if (!cp_payments_is_enabled()) { return 0; } // check for deprecated argument if (!empty($cp_coupon)) { _deprecated_argument(__FUNCTION__, '3.3'); } // calculate the listing fee price $adlistingfee = cp_ad_listing_fee($category_id, $package_id, $cp_price, $price_curr); // calculate the total cost for the ad. $totalcost_out = $adlistingfee + $featuredprice; //set proper return format $totalcost_out = number_format($totalcost_out, 2, '.', ''); //if total cost is less then zero, then make the cost zero (free) if ($totalcost_out < 0) { $totalcost_out = 0; } return $totalcost_out; }
function cp_calc_ad_cost($catid, $ad_pack_id, $featuredprice, $cp_price, $cp_coupon, $price_curr) { if (!cp_payments_is_enabled()) { return 0; } // calculate the listing fee price $adlistingfee = cp_ad_listing_fee($catid, $ad_pack_id, $cp_price, $price_curr); // calculate the total cost for the ad. $totalcost_out = $adlistingfee + $featuredprice; //set proper return format $totalcost_out = number_format($totalcost_out, 2, '.', ''); //if total cost is less then zero, then make the cost zero (free) if ($totalcost_out < 0) { $totalcost_out = 0; } return $totalcost_out; }
/** * Sets listing internal data. * * return void */ protected function set_internal_data() { global $cp_options, $current_user; $listing = $this->get_listing_obj(); // add items needed for function that displays listing preview $this->posted_fields['fid'] = $this->form_id; $this->posted_fields['cat'] = $this->category_id; // set listing unique id if ($unique_id = get_post_meta($listing->ID, 'cp_sys_ad_conf_id', true)) { $this->posted_fields['cp_sys_ad_conf_id'] = $unique_id; } else { $this->posted_fields['cp_sys_ad_conf_id'] = cp_generate_id(); } // set user IP $this->posted_fields['cp_sys_userIP'] = appthemes_get_ip(); // set listing duration if ($this->posted_fields['ad_pack_id']) { $this->posted_fields['cp_sys_ad_duration'] = cp_get_ad_pack_length($this->posted_fields['ad_pack_id']); } else { $this->posted_fields['cp_sys_ad_duration'] = $cp_options->prun_period; } $listing_price_currency = !empty($this->posted_fields['cp_currency']) ? $this->posted_fields['cp_currency'] : $cp_options->curr_symbol; $coupon = false; // legacy coupon value if (cp_payments_is_enabled()) { // see if the featured ad checkbox has been checked if (!empty($this->posted_fields['featured_ad'])) { $this->posted_fields['featured_ad'] = 1; // save featured ad price $this->posted_fields['cp_sys_feat_price'] = $cp_options->sys_feat_price; } // calculate the ad listing fee and put into a variable $this->posted_fields['cp_sys_ad_listing_fee'] = cp_ad_listing_fee($this->category_id, $this->posted_fields['ad_pack_id'], $this->posted_fields['cp_price'], $listing_price_currency); $featured_price = isset($this->posted_fields['cp_sys_feat_price']) ? $this->posted_fields['cp_sys_feat_price'] : 0; $this->posted_fields['cp_sys_total_ad_cost'] = cp_calc_ad_cost($this->category_id, $this->posted_fields['ad_pack_id'], $featured_price, $this->posted_fields['cp_price'], $coupon, $listing_price_currency); $this->posted_fields['cp_sys_total_ad_cost_no_benefit'] = $this->posted_fields['cp_sys_total_ad_cost']; // apply membership benefit if ($cp_options->enable_membership_packs && ($membership = cp_get_user_membership_package($current_user->ID))) { $this->posted_fields['membership_pack'] = $membership->ID; // update the total cost based on the membership pack ID and current total cost $this->posted_fields['cp_sys_total_ad_cost'] = cp_calculate_membership_package_benefit($membership->ID, $this->posted_fields['cp_sys_total_ad_cost']); // add featured cost to static pack type if ($featured_price && $membership->pack_type == 'static') { $this->posted_fields['cp_sys_total_ad_cost'] += $featured_price; } } } // prevent from minus prices if bigger discount applied if (!isset($this->posted_fields['cp_sys_total_ad_cost']) || $this->posted_fields['cp_sys_total_ad_cost'] < 0) { $this->posted_fields['cp_sys_total_ad_cost'] = 0; } }