/**
 * Detect if a course is free or not
 *
 * @param null $course_id
 *
 * @return bool
 */
function learn_press_is_free_course($course_id = null)
{
    if (!$course_id) {
        $course_id = get_the_ID();
    }
    return learn_press_get_course($course_id)->is_free();
}
예제 #2
0
		<th class="course-total"><?php 
_e('Total', 'learn_press');
?>
</th>
	</tr>
	</thead>
	<tbody>

	<?php 
do_action('learn_press_review_order_before_cart_contents');
?>

	<?php 
foreach (LP()->cart->get_items() as $item_id => $cart_item) {
    $cart_item = apply_filters('learn_press_cart_item', $cart_item);
    $_course = learn_press_get_course($item_id);
    if ($_course && $cart_item['quantity'] > 0) {
        ?>
			<tr class="<?php 
        echo esc_attr(apply_filters('learn_press_cart_item_class', 'cart-item', $cart_item));
        ?>
">
				<td class="course-name">
					<?php 
        echo apply_filters('learn_press_cart_item_name', $_course->get_title(), $cart_item) . '&nbsp;';
        ?>
					<?php 
        echo apply_filters('learn_press_cart_item_quantity', ' <strong class="course-quantity">' . sprintf('&times; %s', $cart_item['quantity']) . '</strong>', $cart_item);
        ?>
				</td>
				<td class="course-total">
예제 #3
0
 /**
  * Return true if user can purchase a course
  *
  * @param $course_id
  *
  * @return bool
  */
 function can_purchase_course($course_id)
 {
     $course = learn_press_get_course($course_id);
     $purchaseable = $course->is_purchaseable() && !$this->has_purchased_course($course_id);
     return apply_filters('learn_press_user_can_purchase_course', $purchaseable, $this, $course_id);
 }
예제 #4
0
 function calculate_totals()
 {
     if ($items = $this->_cart_content['items']) {
         $subtotal = 0;
         foreach ($items as $item_id => $item) {
             $course = learn_press_get_course($item_id);
             if ($course) {
                 $_subtotal = $course->get_price() * $item['quantity'];
             }
             $this->_cart_content['items'][$item_id]['subtotal'] = $_subtotal;
             $this->_cart_content['items'][$item_id]['total'] = $_subtotal;
             $subtotal += $_subtotal;
         }
         $this->_cart_content['subtotal'] = $subtotal;
         $this->_cart_content['total'] = $subtotal;
     }
     $this->update_session();
 }
 /**
  * Add new course to order
  */
 static function add_item_to_order()
 {
     // ensure that user has permission
     if (!current_user_can('edit_lp_orders')) {
         die(__('Permission denied', 'learn_press'));
     }
     // verify nonce
     $nonce = learn_press_get_request('nonce');
     if (!wp_verify_nonce($nonce, 'add_item_to_order')) {
         die(__('Check nonce failed', 'learn_press'));
     }
     // validate order
     $order_id = learn_press_get_request('order_id');
     if (!is_numeric($order_id) || get_post_type($order_id) != 'lp_order') {
         die(__('Order invalid', 'learn_press'));
     }
     // validate item
     $item_id = learn_press_get_request('item_id');
     $post = get_post($item_id);
     if (!$post || 'lp_course' !== $post->post_type) {
         die(__('Course invalid', 'learn_press'));
     }
     $course = learn_press_get_course($post->ID);
     $order = learn_press_get_order($order_id);
     $item = array('course_id' => $course->id, 'name' => $course->get_title(), 'quantity' => 1, 'subtotal' => $course->get_price(), 'total' => $course->get_price());
     // Add item
     $item_id = learn_press_add_order_item($order_id, array('order_item_name' => $item['name']));
     $item['id'] = $item_id;
     // Add item meta
     if ($item_id) {
         $item = apply_filters('learn_press_ajax_order_item', $item);
         learn_press_add_order_item_meta($item_id, '_course_id', $item['course_id']);
         learn_press_add_order_item_meta($item_id, '_quantity', $item['quantity']);
         learn_press_add_order_item_meta($item_id, '_subtotal', $item['subtotal']);
         learn_press_add_order_item_meta($item_id, '_total', $item['total']);
         do_action('learn_press_ajax_add_order_item_meta', $item);
     }
     $order_data = learn_press_update_order_items($order_id);
     $currency_symbol = learn_press_get_currency_symbol($order_data['currency']);
     $order_data['subtotal_html'] = learn_press_format_price($order_data['subtotal'], $currency_symbol);
     $order_data['total_html'] = learn_press_format_price($order_data['total'], $currency_symbol);
     ob_start();
     include learn_press_get_admin_view('meta-boxes/order/order-item.php');
     $item_html = ob_get_clean();
     learn_press_send_json(array('result' => 'success', 'item_html' => $item_html, 'order_data' => $order_data));
 }