/** * Retrieves all available plan types. */ function cp_get_plans($plan_types, $args = array()) { if (!$plan_types) { $plan_types = cp_get_plan_types(); } $defaults = array('post_type' => $plan_types, 'nopaging' => true, 'post_status' => 'publish', 'orderby' => 'menu_order'); $args = wp_parse_args($args, $defaults); $plans = new WP_Query($args); $plans_data = array(); foreach ($plans->posts as $key => $post) { $plans_data[$key] = cp_get_plan_data($post->ID); $plans_data[$key]['post'] = $post; } return $plans_data; }
/** * Assigns a plan to the Order * * @since 3.5 */ function add_plan_to_order($order, $checkout, $plan_id = 0, $membership_id = 0, $post_id = 0) { global $cp_options; // clear previous plan if available $this->clear_order_plan($order); // apply plan pricing if available if ($plan_id) { $plan = get_post($plan_id); $plan_data = cp_get_plan_data($plan_id); $plan = $plan->post_name; $price = $plan_data['price']; if ($order->get_items($plan)) { return; } // apply single listing pricings depending on the pricing scheme } else { $plan = $cp_options->price_scheme; $price = $this->posted_fields['cp_sys_ad_listing_fee']; if ($order->get_items($plan)) { return; } } // apply the membership price if available if ($membership_id) { $member_plan = get_post($membership_id); $member_price = cp_calculate_membership_package_benefit($membership_id, $this->posted_fields['cp_sys_total_ad_cost_no_benefit']); $order->add_item($member_plan->post_name, $member_price, $post_id); $price = 0; } // add the plan price $order->add_item($plan, $price, $post_id); }