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;
     }
 }
 function get_paypal_args($order)
 {
     $this->prepare_line_items();
     $user = learn_press_get_current_user();
     $nonce = wp_create_nonce('learn-press-paypal-nonce');
     $custom = array('order_id' => $order->id, 'order_key' => $order->order_key);
     $args = array_merge(array('cmd' => '_cart', 'business' => $this->paypal_email, 'no_note' => 1, 'currency_code' => learn_press_get_currency(), 'charset' => 'utf-8', 'rm' => is_ssl() ? 2 : 1, 'upload' => 1, 'return' => esc_url($this->get_return_url($order)), 'cancel_return' => esc_url(learn_press_is_enable_cart() ? learn_press_get_page_link('cart') : get_site_url()), 'bn' => 'LearnPress_Cart', 'custom' => json_encode($custom), 'notify_url' => get_site_url() . '/?' . learn_press_get_web_hook('paypal') . '=1', 'email' => $user->user_email), $this->get_item_lines());
     //print_r($args);die();
     return apply_filters('learn_press_paypal_args', $args);
 }