/** * Retrieves the plan data for a given Order and/or plan post type. * * @since 3.5 */ function cp_get_order_plan_data($order, $post_types = '') { // retrieve plan data from all plan types if the type was not specified if (!$post_types) { $post_types = cp_get_plan_types(); } $plans = cp_get_plans($post_types); foreach ($plans as $key => $plan) { if (empty($plan['post']->post_name)) { continue; } $plan_slug = $plan['post']->post_name; $items = $order->get_items($plan_slug); if ($items) { return array('type' => $plan_slug, 'data' => $plan); } } return false; }
/** * Clears all plans from an Order to avoid duplicate items when a user updates the selection. * * @since 3.5 */ protected function clear_order_plan($order, $plan_types = '') { // remove pricing plan 'addons' $this->clear_order_addons($order, 'pricing'); foreach (cp_get_plans($plan_types) as $plan) { $order->remove_item($plan['post']->post_name); } }