Exemplo n.º 1
0
 /**
  * Shortcode: educator_courses.
  *
  * @param array $atts
  * @param string $content
  * @return string
  */
 function educator_courses_shortcode($atts, $content = null)
 {
     $atts = shortcode_atts(array('show_price' => 1, 'ids' => '', 'number' => 15, 'categories' => null), $atts);
     $output = '<div class="courses-carousel owl-carousel">';
     $params = array('post_type' => 'ib_educator_course', 'orderby' => 'menu_order', 'posts_per_page' => intval($atts['number']));
     if ($atts['ids']) {
         $ids = explode(' ', $atts['ids']);
         $params['post__in'] = array();
         foreach ($ids as $id) {
             $params['post__in'][] = intval($id);
         }
         $params['posts_per_page'] = -1;
         $params['orderby'] = 'post__in';
     }
     if ($atts['categories']) {
         $categories = explode(' ', $atts['categories']);
         foreach ($categories as $key => $term_id) {
             $categories[$key] = intval($term_id);
         }
         $params['tax_query'] = array(array('taxonomy' => 'ib_educator_category', 'field' => 'term_id', 'terms' => $categories));
     }
     $query = new WP_Query($params);
     if ($query->have_posts()) {
         $course_id = 0;
         while ($query->have_posts()) {
             $query->the_post();
             $course_id = get_the_ID();
             $output .= '<article class="' . esc_attr(implode(' ', get_post_class('post-grid'))) . '">';
             if (has_post_thumbnail()) {
                 $output .= '<div class="post-thumb"><a href="' . esc_url(get_permalink()) . '">' . get_the_post_thumbnail($course_id, 'ib-educator-grid') . '</a></div>';
             }
             $output .= '<div class="post-body">';
             $output .= '<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '">' . the_title('', '', false) . '</a></h2>';
             if (1 == $atts['show_price'] && 'closed' != ib_edu_registration($course_id)) {
                 $output .= '<div class="price">' . ib_edu_format_course_price(ib_edu_get_course_price($course_id)) . '</div>';
             }
             ob_start();
             the_excerpt();
             $output .= '<div class="post-excerpt">' . ob_get_clean() . '</div>';
             $output .= '</div>';
             if (function_exists('educator_course_meta')) {
                 $output .= '<footer class="post-meta">' . educator_course_meta($course_id, array('num_lessons', 'difficulty')) . educator_share('menu') . '</footer>';
             }
             $output .= '</article>';
         }
         wp_reset_postdata();
     }
     $output .= '</div>';
     return $output;
 }
Exemplo n.º 2
0
 /**
  * Process payment.
  *
  * @return array
  */
 public function process_payment($object_id, $user_id = 0, $payment_type = 'course', $atts = array())
 {
     if (!$user_id) {
         $user_id = get_current_user_id();
     }
     if (!$user_id) {
         return array('status' => '', 'redirect' => home_url('/'));
     }
     // Add payment.
     $payment = IB_Educator_Payment::get_instance();
     $payment->user_id = $user_id;
     $payment->payment_type = $payment_type;
     $payment->payment_status = 'complete';
     $payment->payment_gateway = $this->get_id();
     $payment->amount = 0.0;
     $payment->currency = ib_edu_get_currency();
     if ('course' == $payment_type) {
         $payment->course_id = $object_id;
         $payment->amount = ib_edu_get_course_price($object_id);
     } elseif ('membership' == $payment_type) {
         $payment->object_id = $object_id;
         $ms = IB_Educator_Memberships::get_instance();
         $payment->amount = $ms->get_price($object_id);
     }
     if (!empty($atts['ip'])) {
         $payment->ip = $atts['ip'];
     }
     if (0.0 == $payment->amount) {
         $payment->save();
         if ($payment->ID) {
             if ('course' == $payment->payment_type) {
                 // Setup course entry.
                 $entry = IB_Educator_Entry::get_instance();
                 $entry->course_id = $object_id;
                 $entry->user_id = $user_id;
                 $entry->payment_id = $payment->ID;
                 $entry->entry_status = 'inprogress';
                 $entry->entry_date = date('Y-m-d H:i:s');
                 $entry->save();
             } elseif ('membership' == $payment->payment_type) {
                 // Setup membership.
                 $ms->setup_membership($user_id, $object_id);
             }
         }
     }
     return array('status' => 'complete', 'redirect' => get_permalink($object_id), 'payment' => $payment);
 }
Exemplo n.º 3
0
 /**
  * Get payment info table.
  *
  * @param WP_Post $object
  * @param array $args
  * @return string
  */
 public static function payment_info($object, $args = array())
 {
     // Get price.
     if (!isset($args['price'])) {
         if ('ib_educator_course' == $object->post_type) {
             $args['price'] = ib_edu_get_course_price($object->ID);
         } elseif ('ib_edu_membership' == $object->post_type) {
             $args['price'] = IB_Educator_Memberships::get_instance()->get_price($object->ID);
         }
     }
     // Get tax data.
     $tax_enabled = ib_edu_get_option('enable', 'taxes');
     if ($tax_enabled) {
         $edu_tax = IB_Educator_Tax::get_instance();
         $tax_data = $edu_tax->calculate_tax($edu_tax->get_tax_class_for($object->ID), $args['price'], $args['country'], $args['state']);
     } else {
         $tax_data = array('taxes' => array(), 'subtotal' => $args['price'], 'tax' => 0.0, 'total' => $args['price']);
     }
     // Items list.
     $output = '<table class="edu-payment-table">';
     $output .= '<thead><tr><th>' . __('Item', 'ibeducator') . '</th><th>' . __('Price', 'ibeducator') . '</th></tr></thead>';
     if ('ib_educator_course' == $object->post_type) {
         $output .= '<tbody><tr><td>';
         if (ib_edu_get_option('payment_lecturer', 'settings')) {
             $output .= sprintf(__('%s with %s', 'ibeducator'), '<a href="' . esc_url(get_permalink($object->ID)) . '" target="_blank">' . esc_html($object->post_title) . '</a>', esc_html(get_the_author_meta('display_name', $object->post_author)));
         } else {
             $output .= '<a href="' . esc_url(get_permalink($object->ID)) . '" target="_blank">' . esc_html($object->post_title) . '</a>';
         }
         $output .= '<input type="hidden" id="payment-object-id" name="course_id" value="' . intval($object->ID) . '"></td>';
         $output .= '<td>' . ib_edu_format_price($tax_data['subtotal'], false) . '</td></tr></tbody>';
     } elseif ('ib_edu_membership' == $object->post_type) {
         $output .= '<tbody><tr><td>' . esc_html($object->post_title);
         $output .= '<input type="hidden" id="payment-object-id" name="membership_id" value="' . intval($object->ID) . '"></td>';
         $ms = IB_Educator_Memberships::get_instance();
         $membership_meta = $ms->get_membership_meta($object->ID);
         $output .= '<td>' . $ms->format_price($tax_data['subtotal'], $membership_meta['duration'], $membership_meta['period']) . '</td></tr></tbody>';
     }
     $output .= '</table>';
     // Summary.
     $output .= '<dl class="edu-payment-summary edu-dl">';
     if ($tax_data['tax'] > 0.0) {
         $output .= '<dt class="payment-subtotal">' . __('Subtotal', 'ibeducator') . '</dt><dd>' . ib_edu_format_price($tax_data['subtotal'], false) . '</dd>';
         foreach ($tax_data['taxes'] as $tax) {
             $output .= '<dt class="payment-tax">' . esc_html($tax->name) . '</dt><dd>' . ib_edu_format_price($tax->amount, false) . '</dd>';
         }
     }
     $output .= '<dt class="payment-total">' . __('Total', 'ibeducator') . '</dt><dd>' . ib_edu_format_price($tax_data['total'], false) . '</dd>';
     $output .= '</dl>';
     return $output;
 }
Exemplo n.º 4
0
 /**
  * Add payment.
  */
 public function addPayment($input)
 {
     $data = array('user_id' => $input['user_id'], 'payment_type' => $input['payment_type'], 'payment_gateway' => 'paypal', 'payment_status' => $input['payment_status'], 'currency' => 'USD');
     if ('course' == $input['payment_type']) {
         $data['course_id'] = $input['course_id'];
         $data['amount'] = ib_edu_get_course_price($input['course_id']);
     } elseif ('membership' == $input['payment_type']) {
         $data['object_id'] = $input['object_id'];
         $ms = IB_Educator_Memberships::get_instance();
         $data['amount'] = $ms->get_price($input['object_id']);
     }
     $payment = $this->api->add_payment($data);
     return $payment->ID;
 }
Exemplo n.º 5
0
        } elseif (!empty($billing['country'])) {
            $args['country'] = $billing['country'];
        } else {
            $args['country'] = ib_edu_get_location('country');
        }
        // Get state.
        if (isset($_POST['billing_state'])) {
            $args['state'] = $_POST['billing_state'];
        } elseif (!empty($billing['state'])) {
            $args['state'] = $billing['state'];
        } else {
            $args['state'] = ib_edu_get_location('state');
        }
        // Get price.
        if ('ib_educator_course' == $post->post_type) {
            $args['price'] = ib_edu_get_course_price($post->ID);
        } elseif ('ib_edu_membership' == $post->post_type) {
            $args['price'] = Edr_Memberships::get_instance()->get_price($post->ID);
        }
        // Output payment summary.
        echo '<div id="edu-payment-info" class="edu-payment-info">' . Edr_StudentAccount::payment_info($post, $args) . '</div>';
        // Payment gateways.
        $gateways = IB_Educator_Main::get_gateways();
        ?>

				<?php 
        if ($args['price'] && !empty($gateways)) {
            ?>
					<div class="ib-edu-form-field<?php 
            if (in_array('empty_payment_method', $error_codes)) {
                echo ' error';
Exemplo n.º 6
0
    the_post_thumbnail('ib-educator-grid');
    ?>
</a>
	</div>
	<?php 
}
?>

	<div class="post-body">
		<?php 
the_title('<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>');
?>
		<div class="price">
			<?php 
if ('closed' != ib_edu_registration($course_id)) {
    echo ib_edu_format_price(ib_edu_get_course_price($course_id));
}
?>
		</div>
		<div class="post-excerpt"><?php 
the_excerpt();
?>
</div>
	</div>

	<footer class="post-meta">
		<?php 
echo educator_course_meta($course_id, array('num_lessons', 'difficulty'));
echo educator_share('menu');
?>
	</footer>
Exemplo n.º 7
0
/**
 * Find out whether to collect billing data or not.
 *
 * @param mixed $object
 * @return bool
 */
function ib_edu_collect_billing_data($object)
{
    if (is_numeric($object)) {
        $object = get_post($object);
    }
    $result = false;
    if ($object) {
        $price = null;
        if ('ib_edu_membership' == $object->post_type) {
            $price = IB_Educator_Memberships::get_instance()->get_price($object->ID);
        } elseif ('ib_educator_course' == $object->post_type) {
            $price = ib_edu_get_course_price($object->ID);
        }
        if ($price && ib_edu_get_option('enable', 'taxes')) {
            $result = true;
        }
    }
    return $result;
}
Exemplo n.º 8
0
<?php

// Setup form object.
require_once IBEDUCATOR_PLUGIN_DIR . 'includes/ib-educator-form.php';
$form = new IB_Educator_Form();
$form->default_decorators();
// Registration.
$form->set_value('_ib_educator_register', get_post_meta($post->ID, '_ib_educator_register', true));
$form->add(array('type' => 'select', 'name' => '_ib_educator_register', 'label' => __('Registration', 'ibeducator'), 'options' => array('open' => __('Open', 'ibeducator'), 'closed' => __('Closed', 'ibeducator')), 'default' => 'open'));
// Price.
$form->set_value('_ibedu_price', ib_edu_get_course_price($post->ID));
$form->add(array('type' => 'text', 'name' => '_ibedu_price', 'class' => '', 'id' => 'ib-educator-price', 'label' => __('Price', 'ibeducator'), 'before' => esc_html(ib_edu_get_currency_symbol(ib_edu_get_currency())) . ' '));
// Tax Class.
$edu_tax = IB_Educator_Tax::get_instance();
$form->set_value('_ib_educator_tax_class', $edu_tax->get_tax_class_for($post->ID));
$form->add(array('type' => 'select', 'name' => '_ib_educator_tax_class', 'label' => __('Tax Class', 'ibeducator'), 'options' => $edu_tax->get_tax_classes(), 'default' => 'default'));
// Difficulty.
$form->set_value('_ib_educator_difficulty', get_post_meta($post->ID, '_ib_educator_difficulty', true));
$form->add(array('type' => 'select', 'name' => '_ib_educator_difficulty', 'id' => 'ib-educator-difficulty', 'label' => __('Difficulty', 'ibeducator'), 'options' => array_merge(array('' => __('None', 'ibeducator')), ib_edu_get_difficulty_levels())));
// Prerequisite.
$courses = array('' => __('None', 'ibeducator'));
$tmp = get_posts(array('post_type' => 'ib_educator_course', 'post_status' => 'publish', 'posts_per_page' => -1));
foreach ($tmp as $course) {
    $courses[$course->ID] = $course->post_title;
}
$prerequisites = IB_Educator::get_instance()->get_prerequisites($post->ID);
$form->set_value('_ib_educator_prerequisite', array_pop($prerequisites));
$form->add(array('type' => 'select', 'name' => '_ib_educator_prerequisite', 'id' => 'ib-educator-prerequisite', 'label' => __('Prerequisite', 'ibeducator'), 'options' => $courses));
wp_nonce_field('ib_educator_course_meta_box', 'ib_educator_course_meta_box_nonce');
$form->display();
Exemplo n.º 9
0
 /**
  * Get related courses.
  *
  * @param int $post_id
  * @return string
  */
 function educator_related_courses($post_id)
 {
     $terms = get_the_terms($post_id, 'ib_educator_category');
     if (!$terms || is_wp_error($terms)) {
         return;
     }
     $args = array('post_type' => 'ib_educator_course', 'posts_per_page' => 3, 'post__not_in' => array($post_id));
     $terms_ids = array();
     foreach ($terms as $term) {
         $terms_ids[] = $term->term_id;
     }
     $args['tax_query'] = array(array('taxonomy' => 'ib_educator_category', 'terms' => $terms_ids));
     $query = new WP_Query($args);
     if ($query->have_posts()) {
         $output = '<section class="related-courses">';
         $output .= '<h1>' . __('Related Courses', 'ib-educator') . '</h1>';
         $api = IB_Educator::get_instance();
         $course_id = 0;
         while ($query->have_posts()) {
             $query->the_post();
             $course_id = get_the_ID();
             $output .= '<article class="' . esc_attr(implode(' ', get_post_class('clearfix'))) . '">';
             if (has_post_thumbnail()) {
                 $output .= '<div class="post-thumb"><a href="' . esc_url(get_permalink()) . '">' . get_the_post_thumbnail($course_id, 'thumbnail') . '</a></div>';
             }
             $output .= '<div class="post-summary">' . '<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '">' . the_title('', '', false) . '</a></h2>';
             ob_start();
             the_excerpt();
             $output .= '<div class="post-excerpt">' . ob_get_clean() . '</div>';
             $output .= '<div class="post-meta">';
             if ('closed' != ib_edu_registration($course_id)) {
                 $output .= '<span class="price">' . ib_edu_format_course_price(ib_edu_get_course_price($course_id)) . '</span>';
             }
             $output .= educator_course_meta($course_id, array('num_lessons', 'difficulty'));
             $output .= '</div>';
             $output .= '</div>';
             $output .= '</article>';
         }
         wp_reset_postdata();
         $output .= '</section>';
         return $output;
     }
     return '';
 }
Exemplo n.º 10
0
    ?>
</a>
		<div class="ib-edu-course-price">
			<?php 
    if (ib_edu_get_course_price(get_the_ID()) == 0) {
        ?>
				 <span class="label-free"><?php 
        esc_html_e('Free', 'training');
        ?>
</span>
			<?php 
    } else {
        ?>
		
				<span><?php 
        echo ib_edu_format_price(ib_edu_get_course_price(get_the_ID()));
        ?>
</span>
			<?php 
    }
    ?>
	
		</div>
	</div>
	<?php 
}
?>
	<div class="course-inner">
		<div class="course-header">
			<h4><a href="<?php 
echo esc_url($link);
 /**
  * Create payment.
  *
  * @param int $object_id ID of the object the payment is to be associated with.
  * @param int $user_id
  * @param string $payment_type
  * @return IB_Educator_Payment
  */
 public function create_payment($object_id, $user_id, $payment_type, $atts = array())
 {
     $payment = IB_Educator_Payment::get_instance();
     $payment->user_id = $user_id;
     $payment->payment_type = $payment_type;
     $payment->payment_status = 'pending';
     $payment->payment_gateway = $this->get_id();
     $payment->currency = ib_edu_get_currency();
     if ('course' == $payment_type) {
         $payment->course_id = $object_id;
         $payment->amount = ib_edu_get_course_price($object_id);
     } elseif ('membership' == $payment_type) {
         $payment->object_id = $object_id;
         $payment->amount = IB_Educator_Memberships::get_instance()->get_price($object_id);
     }
     $tax_data = null;
     if (ib_edu_collect_billing_data($object_id)) {
         // Save billing data.
         $billing = get_user_meta($user_id, '_ib_educator_billing', true);
         if (!is_array($billing)) {
             $billing = array();
         }
         $payment->first_name = get_user_meta($user_id, 'first_name', true);
         $payment->last_name = get_user_meta($user_id, 'last_name', true);
         $payment->address = isset($billing['address']) ? $billing['address'] : '';
         $payment->address_2 = isset($billing['address_2']) ? $billing['address_2'] : '';
         $payment->city = isset($billing['city']) ? $billing['city'] : '';
         $payment->state = isset($billing['state']) ? $billing['state'] : '';
         $payment->postcode = isset($billing['postcode']) ? $billing['postcode'] : '';
         $payment->country = isset($billing['country']) ? $billing['country'] : '';
         // Calculate tax.
         $edu_tax = IB_Educator_Tax::get_instance();
         $tax_data = $edu_tax->calculate_tax($edu_tax->get_tax_class_for($object_id), $payment->amount, $payment->country, $payment->state);
         $payment->tax = $tax_data['tax'];
         $payment->amount = $tax_data['total'];
     }
     if (!empty($atts['ip'])) {
         $payment->ip = $atts['ip'];
     }
     $payment->save();
     // Save tax data.
     if ($tax_data) {
         foreach ($tax_data['taxes'] as $tax) {
             $payment->update_line(array('object_id' => $tax->ID, 'line_type' => 'tax', 'amount' => $tax->amount, 'name' => $tax->name));
         }
     }
     return $payment;
 }
the_title();
?>
</h1>
						<?php 
do_action('ib_educator_after_course_title');
?>
						<div class="course-rating">
							<?php 
if (function_exists('the_ratings')) {
    the_ratings();
}
?>
						</div>
						<?php 
$output = '<ul class="list">';
$price = ib_edu_get_course_price($course_id);
$price = 0 == $price ? esc_html__('Free', 'training') : ib_edu_format_course_price($price);
$register_url = ib_edu_get_endpoint_url('edu-course', $course_id, get_permalink(ib_edu_page_id('payment')));
$output .= '<li class="price"><i class="uicon icon-price"></i><span class="lab">' . esc_html__('Price: ', 'training') . '</span> <span class="val">' . $price . '</span></li>';
if (isset($options['duration']) && $options['duration']) {
    $output .= '<li class="price"><i class="uicon icon-duration"></i><span class="lab">' . esc_html__('Duration: ', 'training') . '</span> <span class="val">' . $options['duration'] . '</span></li>';
}
if (isset($options['is_certificates'])) {
    $output .= '<li class="price hidden"><i class="uicon icon-certificates"></i><span class="lab">' . esc_html__('Certificates: ', 'training') . '</span> <span class="val">' . ($options['is_certificates'] ? esc_html__('Yes', 'training') : esc_html__('No', 'training')) . '</span></li>';
}
$output .= '<li class="lesson"><i class="uicon icon-students"></i><span class="lab">' . esc_html__('Students: ', 'training') . '</span> <span class="val">' . count($students) . '</span></li>';
$output .= '<li class="lesson"><i class="uicon icon-lesson"></i><span class="lab">' . esc_html__('Lesson: ', 'training') . '</span> <span class="val">' . $api->get_num_lessons(get_the_id()) . '</span></li>';
$output .= '</ul>';
echo trim($output);
?>