function payment_meta_box() { $prefix = '_lpr_'; $meta_box = array('id' => 'course_payment', 'title' => 'Course Payment Settings', 'priority' => 'high', 'pages' => array(LPR_COURSE_CPT), 'fields' => array(array('name' => __('Enrolled Require', 'learn_press'), 'id' => "{$prefix}course_enrolled_require", 'type' => 'radio', 'desc' => 'Require users logged in to study or public to all', 'options' => array('yes' => __('Yes, enroll is required', 'learn_press'), 'no' => __('No', 'learn_press')), 'std' => 'yes', 'class' => 'hide-if-js'), array('name' => __('Course Payment', 'learn_press'), 'id' => "{$prefix}course_payment", 'type' => 'radio', 'desc' => 'If Paid be checked, An administrator will review then set course price and commission', 'options' => array('free' => __('Free', 'learn_press'), 'not_free' => __('Paid', 'learn_press')), 'std' => 'free', 'class' => 'lpr-course-payment-field hide-if-js'))); if (current_user_can('manage_options')) { $message = 'If free, this field is empty or set 0. (Only admin can edit this field)'; $price = 0; if (isset($_GET['post'])) { $course_id = $_GET['post']; $type = get_post_meta($course_id, '_lpr_course_payment', true); if ($type != 'free') { $suggest_price = get_post_meta($course_id, '_lpr_course_suggestion_price', true); if (isset($suggest_price)) { $message = 'This course is enrolled require and the suggestion price is ' . '<span>' . learn_press_get_currency_symbol() . $suggest_price . '</span>'; $price = $suggest_price; } } else { $message = 'This course is free.'; } } array_push($meta_box['fields'], array('name' => __('Course Price', 'learn_press'), 'id' => "{$prefix}course_price", 'type' => 'number', 'min' => 0, 'step' => 0.01, 'desc' => $message, 'std' => $price, 'class' => 'lpr-course-price-field hide-if-js')); } else { array_push($meta_box['fields'], array('name' => __('Course Suggestion Price', 'learn_press'), 'id' => "{$prefix}course_suggestion_price", 'type' => 'number', 'min' => 0, 'step' => 0.01, 'desc' => 'The course price you want to suggest for admin to set.', 'class' => 'lpr-course-price-field hide-if-js', 'std' => 0)); } return apply_filters('learn_press_course_payment_meta_box_args', $meta_box); }
private function _get_currency_positions() { $positions = array(); foreach (learn_press_currency_positions() as $pos => $text) { switch ($pos) { case 'left': $text = sprintf('%s ( %s%s )', $text, learn_press_get_currency_symbol(), '69.99'); break; case 'right': $text = sprintf('%s ( %s%s )', $text, '69.99', learn_press_get_currency_symbol()); break; case 'left_with_space': $text = sprintf('%s ( %s %s )', $text, learn_press_get_currency_symbol(), '69.99'); break; case 'right_with_space': $text = sprintf('%s ( %s %s )', $text, '69.99', learn_press_get_currency_symbol()); break; } $positions[$pos] = $text; } return $positions; }
function learn_press_format_price($price, $with_currency = false) { if (!is_numeric($price)) { $price = 0; } $settings = LP()->settings; $before = $after = ''; if ($with_currency) { if (gettype($with_currency) != 'string') { $currency = learn_press_get_currency_symbol(); } else { $currency = $with_currency; } switch ($settings->get('currency_pos')) { default: $before = $currency; break; case 'left_with_space': $before = $currency . ' '; break; case 'right': $after = $currency; break; case 'right_with_space': $after = ' ' . $currency; } } $price = $before . number_format($price, $settings->get('number_of_decimals', 2), $settings->get('decimals_separator', '.'), $settings->get('thousands_separator', ',')) . $after; return $price; }
<?php if (isset($order_items)) { $currency_symbol = learn_press_get_currency_symbol($order_items->currency); } else { $currency_symbol = learn_press_get_currency_symbol(); } global $post; ?> <div id="learn-press-order" class="order-details"> <div class="order-data"> <h3 class="order-data-number"><?php echo sprintf(__('Order %s', 'learn_press'), $order->get_order_number()); ?> </h3> <div class="order-data-date"><?php echo sprintf(__('Date %s', 'learn_press'), $order->order_date); ?> </div> <div class="order-data-status <?php echo sanitize_title($order->post_status); ?> "><?php echo sprintf(__('Status %s', 'learn_press'), $order->get_order_status()); ?> </div> <div class="order-data-payment-method"><?php echo learn_press_payment_method_from_slug($post->ID);
function get_formatted_order_total() { $currency_symbol = learn_press_get_currency_symbol($this->order_currency); return learn_press_format_price($this->order_total, $currency_symbol); }
function order_details($post) { $user = learn_press_get_user(get_post_meta($post->ID, '_learn_press_customer_id', true)); $order_items = learn_press_get_order_items($post->ID); $status = strtolower(get_post_meta($post->ID, '_learn_press_transaction_status', true)); if ($status && !in_array($status, array('completed', 'pending'))) { $status = 'Pending'; } $currency_symbol = learn_press_get_currency_symbol($order_items->currency); ?> <div class="order-details"> <div class="order-data"> <div class="order-data-number"><?php echo learn_press_transaction_order_number($post->ID); ?> </div> <div class="order-data-date"><?php echo learn_press_transaction_order_date($post->post_date); ?> </div> <div class="order-data-status <?php echo sanitize_title($status); ?> "><?php echo $status; ?> </div> <div class="order-data-payment-method"><?php echo learn_press_payment_method_from_slug($post->ID); ?> </div> </div> <div class="order-user-data clearfix"> <div class="order-user-avatar"> <?php echo get_avatar($user->ID, 120); ?> </div> <div class="order-user-meta"> <h2 class="user-display-name"> <?php echo empty($user->display_name) ? __('Unknown', 'learn_press') : $user->display_name; ?> </h2> <div class="user-email"> <?php echo empty($user->user_email) ? __('Unknown', 'learn_press') : $user->user_email; ?> </div> <div class="user-ip-address"> <?php echo get_post_meta($post->ID, '_learn_press_customer_ip', true); ?> </div> </div> </div> <div class="order-products"> <table> <thead> <tr> <th colspan="2"><?php _e('Courses', 'learn_press'); ?> </th> <th class="align-right"><?php _e('Amount', 'learn_press'); ?> </th> </tr> </thead> <tbody> <?php if ($products = learn_press_get_transition_products($post->ID)) { foreach ($products as $pro) { ?> <tr> <td colspan="2"> <a href="<?php the_permalink($pro->ID); ?> "><?php echo get_the_title($pro->ID); ?> </a> </td> <td class="align-right"><?php echo $pro->amount ? learn_press_format_price($pro->amount, $currency_symbol) : __('Free!', 'learn_press'); ?> </td> </tr> <?php } } ?> </tbody> <tfoot> <tr> <td></td> <td width="300" class="align-right"><?php _e('Sub Total', 'learn_press'); ?> </td> <td width="100" class="align-right"><?php echo learn_press_format_price($order_items->sub_total, $currency_symbol); ?> </td> </tr> <tr> <td></td> <td class="align-right"><?php _e('Total', 'learn_press'); ?> </td> <td class="align-right total"><?php echo learn_press_format_price($order_items->total, $currency_symbol); ?> </td> </tr> <tr> <td></td> <td class="align-right" colspan="2"> <?php _e('Status', 'learn_press'); ?> <select name="learn_press_order_status"> <?php foreach (learn_press_get_order_statuses() as $status => $label) { ?> <option value="<?php echo $status; ?> " <?php selected($status == get_post_status($post->ID) ? 1 : 0, 1); ?> ><?php echo $label; ?> </option> <?php } ?> </select> <button id="update-order-status" class="button button-primary" type="button"><?php _e('Apply', 'learn_press'); ?> </button> </td> </tr> </tfoot> </table> </div> </div> <?php }
function get_formatted_order_total() { $order_items = learn_press_get_order_items($this->post->ID); $currency_symbol = learn_press_get_currency_symbol($order_items->currency); return learn_press_format_price($order_items->sub_total, $currency_symbol); }
selected($settings->get('currency_pos') == $pos ? 1 : 0, 1); ?> > <?php switch ($pos) { case 'left': printf('%s ( %s%s )', $text, learn_press_get_currency_symbol(), '69.99'); break; case 'right': printf('%s ( %s%s )', $text, '69.99', learn_press_get_currency_symbol()); break; case 'left_with_space': printf('%s ( %s %s )', $text, learn_press_get_currency_symbol(), '69.99'); break; case 'right_with_space': printf('%s ( %s %s )', $text, '69.99', learn_press_get_currency_symbol()); break; } ?> </option> <?php } ?> </select> </td> </tr> <tr> <th><label><?php _e('Thousands Separator', 'learn_press'); ?> </label></th>
function output() { $settings = LPR_Admin_Settings::instance('general'); // get_option( '_lpr_general_settings', array() ); ?> <h3><?php _e('General Settings', 'learn_press'); ?> </h3> <table class="form-table"> <tbody> <?php do_action('learn_press_before_general_settings_fields', $settings); ?> <tr> <th scope="row"><label for="lpr_set_page"><?php _e('Profile methods', 'learn_press'); ?> </label></th> <td> <select id="lpr_set_page" name="learn_press[set_page]"> <?php if ($profile_methods = apply_filters('learn_press_profile_methods', array())) { } ?> <?php foreach ($profile_methods as $k => $name) { ?> <?php $selected = selected($settings->get('set_page') == $k ? 1 : 0, 1, false); ?> <option <?php echo $selected; ?> value="<?php echo $k; ?> "><?php echo $name; ?> </option> <?php } ?> </select> </td> </tr> <tr> <th><label for="lpr_currency"><?php _e('Currency', 'learn_press'); ?> </label></th> <td> <?php $payment = get_option('_lpr_payment_settings', array()); $disable = ''; if (isset($payment['woocommerce']['active']) && learn_press_woo_is_active()) { $disable = 'readonly"'; } ?> <select <?php echo $disable; ?> id="lpr_currency" name="learn_press[currency]"> <?php if ($payment_currencies = learn_press_get_payment_currencies()) { foreach ($payment_currencies as $code => $symbol) { ?> <?php $selected = selected($settings->get('currency') == $code ? 1 : 0, 1, false); ?> <option <?php echo $selected; ?> value="<?php echo $code; ?> "><?php echo $symbol; ?> </option> <?php } } ?> </select> <p class="description"><?php _e('For integrated payment method', 'learn_press'); ?> </p> </td> </tr> <tr> <th><label for="learn_press_currency_pos"><?php _e('Currency Position', 'learn_press'); ?> </label></th> <td> <select id="learn_press_currency_pos"name="learn_press[currency_pos]" tabindex="-1" title="Currency Position"> <?php foreach (learn_press_currency_positions() as $pos => $text) { ?> <option value="<?php echo $pos; ?> " <?php selected($settings->get('currency_pos') == $pos ? 1 : 0, 1); ?> > <?php switch ($pos) { case 'left': printf('%s ( %s%s )', $text, learn_press_get_currency_symbol(), '69.99'); break; case 'right': printf('%s ( %s%s )', $text, '69.99', learn_press_get_currency_symbol()); break; case 'left_with_space': printf('%s ( %s %s )', $text, learn_press_get_currency_symbol(), '69.99'); break; case 'right_with_space': printf('%s ( %s %s )', $text, '69.99', learn_press_get_currency_symbol()); break; } ?> </option> <?php } ?> <!-- <option value="right">Right (99.99R)</option> <option value="left_space">Left with space (R 99.99)</option> <option value="right_space">Right with space (99.99 R)</option>--> </select> </td> </tr> <tr> <th><label for="lpr_thousands_sep"><?php _e('Thousands Separator', 'learn_press'); ?> </label></th> <td> <input id="lpr_thousands_sep"class="regular_text" type="text" name="learn_press[thousands_separator]" value="<?php echo $settings->get('thousands_separator', ','); ?> " /> </td> </tr> <tr> <th><label for="lpr_decimals_sep"><?php _e('Decimals Separator', 'learn_press'); ?> </label></th> <td> <input id="lpr_decimals_sep" class="regular_text" type="text" name="learn_press[decimals_separator]" value="<?php echo $settings->get('decimals_separator', '.'); ?> " /> </td> </tr> <tr> <th><label for="lpr_decimals_num"><?php _e('Number of Decimals', 'learn_press'); ?> </label></th> <td> <input id="lpr_decimals_num"class="regular_text" type="text" name="learn_press[number_of_decimals]" value="<?php echo $settings->get('number_of_decimals', 2); ?> " /> </td> </tr> <?php do_action('learn_press_after_general_settings_fields', $settings); ?> </tbody> </table> <?php }
/** * Render column data * */ function columns_content($column) { global $post; $the_order = learn_press_get_order($post->ID); //print_r($the_order->get_items());die(); switch ($column) { case 'order_student': if ($the_order->user_id) { $user = learn_press_get_user($the_order->user_id); printf('<a href="user-edit.php?user_id=%d">%s (%s)</a>', $the_order->user_id, $user->user_login, $user->display_name); printf('<br /><span>%s</span>', $user->user_email); } else { _e('Guest', 'learn_press'); } break; case 'order_status': echo learn_press_get_order_status_label($post->ID); break; case 'order_date': $t_time = get_the_time('Y/m/d g:i:s a'); $m_time = $post->post_date; $time = get_post_time('G', true, $post); $time_diff = current_time('timestamp') - $time; if ($time_diff > 0 && $time_diff < DAY_IN_SECONDS) { $h_time = sprintf(__('%s ago', 'learn_press'), human_time_diff($time)); } else { $h_time = mysql2date('Y/m/d', $m_time); } echo '<abbr title="' . esc_attr($t_time) . '">' . esc_html(apply_filters('learn_press_order_column_time', $h_time, $the_order)) . '</abbr>'; break; case 'order_items': $links = array(); foreach ($the_order->get_items() as $item) { $links[] = '<a href="' . get_the_permalink($item['course_id']) . '">' . get_the_title($item['course_id']) . '</a>'; } echo join("<br />", $links); break; case 'order_total': echo learn_press_format_price($the_order->order_total, learn_press_get_currency_symbol($the_order->order_currency)); break; case 'order_title': $order_number = sprintf("%'.010d", $the_order->ID); ?> <div class="tips"> <a href="post.php?post=<?php echo $the_order->ID; ?> &action=edit"><strong><?php echo learn_press_transaction_order_number($order_number); ?> </strong></a> </div> <?php break; } }
<tr> <th class="course-name"><?php _e('Course', 'learn_press'); ?> </th> <th class="course-total"><?php _e('Total', 'learn_press'); ?> </th> </tr> </thead> <tbody> <?php if ($order_items = $order->get_items()) { $items = $order_items->products; $currency_symbol = learn_press_get_currency_symbol($order_items->currency); foreach ($items as $item_id => $item) { $_course = apply_filters('learn_press_order_item_course', get_post($item_id), $item); //$item_meta = new WC_Order_Item_Meta( $item['item_meta'], $_product ); //print_r($item); if (apply_filters('learn_press_order_item_visible', true, $item)) { ?> <tr class="<?php echo esc_attr(apply_filters('learn_press_order_item_class', 'order_item', $item, $order)); ?> "> <td class="course-name"> <?php echo apply_filters('learn_press_order_item_name', sprintf('<a href="%s">%s</a>', get_permalink($item['id']), $item['product_name']), $item); ?> </td>
/** * 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)); }
<thead> <tr> <th class="course-name"><?php _e('Course', 'learn_press'); ?> </th> <th class="course-total"><?php _e('Total', 'learn_press'); ?> </th> </tr> </thead> <tbody> <?php if ($items = $order->get_items()) { $currency_symbol = learn_press_get_currency_symbol($order->order_currency); foreach ($items as $item_id => $item) { //$_course = apply_filters( 'learn_press_order_item_course', get_post( $item_id ), $item ); if (apply_filters('learn_press_order_item_visible', true, $item)) { ?> <tr class="<?php echo esc_attr(apply_filters('learn_press_order_item_class', 'order_item', $item, $order)); ?> "> <td class="course-name"> <?php echo apply_filters('learn_press_order_item_name', sprintf('<a href="%s">%s</a>', get_permalink($item['course_id']), $item['name']), $item); ?> </td> <td class="product-total"> <?php