Example #1
0
 /**
  * Add course to cart
  *
  * @param int $course_id
  * @param int $quantity
  * @param     array
  */
 function add_to_cart($course_id, $quantity = 1, $item_data = array())
 {
     if (!learn_press_is_enable_cart()) {
         $this->empty_cart();
     }
     $course = learn_press_get_course($course_id);
     /*
     		if ( !empty( $this->_cart_content['items'][$course_id] ) ) {
     			$quantity += $this->_cart_content['items'][$course_id]['quantity'];
     		}*/
     $quantity = 1;
     $this->_cart_content['items'][$course_id] = apply_filters('learn_press_add_cart_item', array('item_id' => $course_id, 'quantity' => $quantity, 'subtotal' => $course->get_price() * $quantity, 'total' => $course->get_price() * $quantity, 'data' => $item_data));
     do_action('learn_press_add_to_cart', $course_id, $quantity, $item_data, $this);
     $button = '';
     if (learn_press_is_enable_cart()) {
         if (LP()->settings->get('redirect_after_add') == 'yes') {
             $redirect = learn_press_get_page_link('cart');
             $button = sprintf('<a href="%s">%s</a>', get_the_permalink($course_id), __('Back to class', 'learn_press'));
         } else {
             $redirect = get_the_permalink($course_id);
             $button = sprintf('<a href="%s">%s</a>', learn_press_get_page_link('cart'), __('View cart', 'learn_press'));
         }
     } else {
         $redirect = learn_press_get_page_link('checkout');
     }
     $redirect = apply_filters('learn_press_add_to_cart_redirect', $redirect, $course_id);
     learn_press_add_notice(sprintf(__('<strong>%s</strong> has been added to your cart. %s', 'learn_press'), get_the_title($course_id), $button));
     if (is_ajax()) {
         learn_press_send_json(array('redirect' => $redirect, 'result' => 'success', 'messages' => learn_press_get_notices(true)));
     } else {
         wp_redirect($redirect);
         die;
     }
 }
/**
 * Display a message immediately with out push into queue
 *
 * @param        $message
 * @param string $type
 */
function learn_press_display_message($message, $type = 'success')
{
    // get all notices added into queue
    $notices = LP_Session::get('notices');
    LP_Session::set('notices', null);
    // add new notice and display
    learn_press_add_notice($message, $type);
    echo learn_press_get_notices(true);
    // store back notices
    LP_Session::set('notices', $notices);
}