/** * Displays Continue button on order summary page. * * @return void */ function cp_payments_display_order_summary_continue_button() { $url = ''; $text = ''; $step = _appthemes_get_step_from_query(); if (!is_singular(APPTHEMES_ORDER_PTYPE) && (!empty($step) && 'order-summary' !== $step)) { return; } $order = get_order(); if ($membership = cp_get_membership_package_from_order($order)) { $package = cp_get_user_membership_package($order->get_author()); if ($package) { $url = CP_ADD_NEW_URL; $text = __('Post a new Ad', APP_TD); } else { $url = CP_DASHBOARD_URL; $text = __('Visit your dashboard', APP_TD); } } else { if ($listing_id = _cp_get_order_ad_id($order)) { $url = get_permalink($listing_id); $text = __('View ad listing', APP_TD); } } echo html('p', html('em', __('Thank you for your purchase!', APP_TD))); if ($url && $text) { if (!in_array($order->get_status(), array(APPTHEMES_ORDER_PENDING, APPTHEMES_ORDER_FAILED))) { echo html('p', html('em', __('Your order has been completed!', APP_TD))); } echo html('button', array('type' => 'submit', 'class' => 'btn_orange', 'onClick' => "location.href='" . $url . "';return false;"), $text); } }
function notices() { global $cp_options, $current_user; if ($cp_options->charge_ads && $cp_options->enable_membership_packs) { $membership = cp_get_user_membership_package($current_user->ID); $step = _appthemes_get_step_from_query(); if ($membership && in_array($step, array('listing-details', 'select-category'))) { appthemes_display_notice('success', sprintf(__('You have active membership pack "%s". Membership benefit will apply on the review page before publishing an ad.', APP_TD), $membership->pack_name)); } } parent::notices(); }
/** * Checks and redirects to membership purchase page if not meet membership requirement. * * @return void */ function cp_redirect_membership() { global $current_user, $cp_options; $current_requirement = false; if (!$cp_options->enable_membership_packs) { return; } if (isset($_POST['cat'])) { $current_requirement = get_membership_requirement($_POST['cat']); } if ($cp_options->required_membership_type == 'all') { $current_requirement = 'all'; } if (!$current_requirement) { return; } $current_membership = cp_get_user_membership_package($current_user->ID); if (!$current_membership || !$current_membership->pack_satisfies_required) { $redirect_url = add_query_arg(array('membership' => 'required', 'cat' => $current_requirement), CP_MEMBERSHIP_PURCHASE_URL); wp_redirect($redirect_url); exit; } }
/** * 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; } }
/** * Updates user membership. * * @param int $user_id * @param object $package * * @return bool */ function cp_update_user_membership($user_id, $package) { $user = get_user_by('id', $user_id); if (!$user || !$package) { return false; } $current_membership = cp_get_user_membership_package($user_id); if ($current_membership && $current_membership->ID == $package->ID) { // user have active that same membership, so extend date $base_date = $user->membership_expires; } else { $base_date = current_time('mysql'); } $new_expiration_date = appthemes_mysql_date($base_date, $package->duration); // update user membership package id and expiration date update_user_meta($user_id, 'active_membership_pack', $package->ID); update_user_meta($user_id, 'membership_expires', $new_expiration_date); return true; }