public function remove_from_cart($expired_app)
 {
     $cart = MP_Cart::get_instance();
     $items = $cart->get_items();
     foreach ($items as $variation => $amount) {
         $app_id = MP_Product::get_variation_meta($variation, 'name');
         if ($app_id == $expired_app->ID) {
             $cart->remove_item($variation);
         }
     }
 }
 function signup_pre_redirect_to_cart($args = array())
 {
     global $mp;
     if (!$mp) {
         return;
     }
     $course_id = 0;
     if (!empty($args)) {
         $course_id = isset($args['course_id']) ? $args['course_id'] : false;
     } else {
         $course_id = !empty($_POST['course_id']) ? (int) $_POST['course_id'] : false;
     }
     $course = new Course($course_id);
     $product_id = $course->mp_product_id();
     // Try some MP alternatives
     $product_id = empty($product_id) ? (int) get_post_meta($course_id, 'mp_product_id', true) : $product_id;
     $product_id = empty($product_id) ? (int) get_post_meta($course_id, 'marketpress_product', true) : $product_id;
     // Set ID's to be used in final step of checkout
     $cookie_id = 'cp_checkout_keys_' . COOKIEHASH;
     $post_keys = array((int) $product_id, (int) $course_id);
     $expire = time() + 2592000;
     //1 month expire
     setcookie($cookie_id, serialize($post_keys), $expire, COOKIEPATH, COOKIE_DOMAIN);
     $_COOKIE[$cookie_id] = serialize($post_keys);
     // Add course to cart
     $product = get_post($product_id);
     $quantity = 1;
     $variation = 0;
     // $cart = $mp->get_cart_cookie();
     switch (CoursePress_MarketPress_Integration::get_base()) {
         case '3.0':
             $cart = MP_Cart::get_instance();
             $cart->add_item($product_id);
             break;
         case '2.0':
             $cart = array();
             // remove all cart items
             $cart[$product_id][$variation] = $quantity;
             $mp->set_cart_cookie($cart);
             break;
     }
 }
 /**
  * Returns related Product instead of standard payment forms for appropriate events.
  */
 function add_event_product_to_cart($event_id, $user_id)
 {
     if (!$this->_is_mp_present()) {
         return;
     }
     $event = new Eab_EventModel(get_post($event_id));
     $recurring = $event->is_recurring_child();
     $product_id = false;
     if ($recurring) {
         $parent_product_id = get_post_meta($recurring, 'eab_product_id', true);
         $query = new WP_Query(array('post_type' => apply_filters('mp_product_variation_post_type', 'mp_product_variation'), 'posts_per_page' => 1, 'post_parent' => $parent_product_id, 'meta_query' => array(array('key' => 'sku', 'value' => $event_id)), 'fields' => 'ids'));
         $product_id = !empty($query->posts[0]) ? $query->posts[0] : false;
     } else {
         $product_id = get_post_meta($event_id, 'eab_product_id', true);
     }
     if (!$product_id) {
         return;
     }
     $cart = MP_Cart::get_instance();
     $items = $cart->get_items();
     if (is_array($items) && false === array_search($product_id, array_keys($items))) {
         // Only add once, not if it's already in the cart
         $product = new MP_Product($product_id);
         if ($product->has_variations()) {
             $cart->add_item($_POST['action_variation']);
         } else {
             $cart->add_item($product_id);
         }
     }
 }