Skip to content

Commit

Permalink
= 4.2.7.5 =
Browse files Browse the repository at this point in the history
~ Added: Price prefix, Price suffix.
  • Loading branch information
tungnxt89 committed Dec 16, 2024
1 parent 1c38288 commit 48653a6
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 77 deletions.
4 changes: 2 additions & 2 deletions assets/src/scss/frontend/_curriculum.scss
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@
margin-bottom: 10px;

.origin-price,
.price {
/*.price {
vertical-align: middle;
}
}*/

.origin-price {
margin-right: 10px;
Expand Down
2 changes: 1 addition & 1 deletion inc/Models/CourseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public function get_section_items(): array {
* @version 1.0.0
*/
public function get_evaluation_type(): string {
return (float) $this->get_meta_value_by_key( CoursePostModel::META_KEY_Evaluation_TYPE, 'evaluate_lesson' );
return (float) $this->get_meta_value_by_key( CoursePostModel::META_KEY_EVALUATION_TYPE, 'evaluate_lesson' );
}

/**
Expand Down
50 changes: 3 additions & 47 deletions inc/Models/CoursePostModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CoursePostModel extends PostModel {
const META_KEY_SALE_PRICE = '_lp_sale_price';
const META_KEY_SALE_START = '_lp_sale_start';
const META_KEY_SALE_END = '_lp_sale_end';
const META_KEY_Evaluation_TYPE = '_lp_course_result';
const META_KEY_EVALUATION_TYPE = '_lp_course_result';
const META_KEY_PASSING_CONDITION = '_lp_passing_condition';
const META_KEY_DURATION = '_lp_duration';
const META_KEY_BLOCK_EXPIRE_DURATION = '_lp_block_expire_duration';
Expand All @@ -60,6 +60,8 @@ class CoursePostModel extends PostModel {
const META_KEY_TARGET = '_lp_target_audiences';
const META_KEY_FEATURES = '_lp_key_features';
const META_KEY_FAQS = '_lp_faqs';
const META_KEY_PRICE_PREFIX = '_lp_price_prefix';
const META_KEY_PRICE_SUFFIX = '_lp_price_suffix';

/**
* Get the price of course.
Expand Down Expand Up @@ -161,52 +163,6 @@ public function is_free(): bool {
return apply_filters( 'learnPress/course/is-free', $this->get_price() == 0, $this );
}

/**
* Get html course price
*
* @return string
* @since 4.1.5
* @version 1.0.1
* @author tungnx
*/
public function get_price_html(): string {
$price_html = '';

if ( $this->is_free() ) {
if ( is_float( $this->get_sale_price() ) ) {
$price_html .= sprintf( '<span class="origin-price">%s</span>', $this->get_regular_price_html() );
}

$price_html .= sprintf( '<span class="free">%s</span>', esc_html__( 'Free', 'learnpress' ) );
$price_html = apply_filters( 'learn_press_course_price_html_free', $price_html, $this );
} elseif ( $this->get_meta_value_by_key( self::META_KEY_NO_REQUIRED_ENROLL, 'no' ) === 'yes' ) {
$price_html .= '';
} else {
if ( $this->has_sale_price() ) {
$price_html .= sprintf( '<span class="origin-price">%s</span>', $this->get_regular_price_html() );
}

$price_html .= sprintf( '<span class="price">%s</span>', learn_press_format_price( $this->get_price(), true ) );
$price_html = apply_filters( 'learn_press_course_price_html', $price_html, $this->has_sale_price(), $this->get_id() );
}

return sprintf( '<span class="course-item-price">%s</span>', $price_html );
}

/**
* Get the regular price format of course.
*
* @return mixed
* @version 1.0.0
* @author tungnx
* @since 4.1.5
*/
public function get_regular_price_html() {
$price = learn_press_format_price( $this->get_regular_price(), true );

return apply_filters( 'learnPress/course/regular-price', $price, $this );
}

/**
* Get post course by ID
*
Expand Down
2 changes: 1 addition & 1 deletion inc/Models/UserItems/UserCourseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public function calculate_course_results( bool $force_cache = false ) {
$count_items = $courseModel->get_total_items();
$count_items_completed = $this->count_items_completed();

$evaluate_type = $courseModel->get_meta_value_by_key( CoursePostModel::META_KEY_Evaluation_TYPE, 'evaluate_lesson' );
$evaluate_type = $courseModel->get_meta_value_by_key( CoursePostModel::META_KEY_EVALUATION_TYPE, 'evaluate_lesson' );
switch ( $evaluate_type ) {
case 'evaluate_lesson':
$results_evaluate = $this->evaluate_course_by_lesson( $count_items_completed, $courseModel->count_items( LP_LESSON_CPT ) );
Expand Down
70 changes: 68 additions & 2 deletions inc/TemplateHooks/Course/SingleCourseTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,22 @@ public function html_price( $course ): string {
$price_html .= $this->html_regular_price( $course );
}

$price_html .= sprintf( '<span class="price">%s</span>', learn_press_format_price( $course->get_price(), true ) );
$price_html = apply_filters( 'learn_press_course_price_html', $price_html, $course->has_sale_price(), $course->get_id() );
$price_html .= sprintf(
'<span class="price">%s</span>',
learn_press_format_price( $course->get_price(), true )
);
$price_html = sprintf(
'%1$s %2$s %3$s',
$this->html_price_prefix( $course ),
$price_html,
$this->html_price_suffix( $course )
);
$price_html = apply_filters(
'learn_press_course_price_html',
$price_html,
$course->has_sale_price(),
$course->get_id()
);
}

// @since 4.2.7
Expand Down Expand Up @@ -1145,6 +1159,58 @@ public function html_material( CourseModel $course, UserModel $user = null ): st
return $html;
}

/**
* Get html level course.
*
* @param LP_Course|CourseModel $course
*
* @return string
* @since 4.2.7.5
* @version 1.0.0
*/
public function html_price_prefix( $course ): string {
$html = '';

try {
$price_prefix_str = $course->get_meta_value_by_key( CoursePostModel::META_KEY_PRICE_PREFIX, '' );
if ( empty( $price_prefix_str ) ) {
return $html;
}

$html = sprintf( '<span class="course-price-prefix">%s</span>', $price_prefix_str );
} catch ( Throwable $e ) {
error_log( __METHOD__ . ': ' . $e->getMessage() );
}

return $html;
}

/**
* Get html level course.
*
* @param LP_Course|CourseModel $course
*
* @return string
* @since 4.2.7.5
* @version 1.0.0
*/
public function html_price_suffix( $course ): string {
$html = '';

try {
$price_suffix_str = $course->get_meta_value_by_key( CoursePostModel::META_KEY_PRICE_SUFFIX, '' );
if ( empty( $price_suffix_str ) ) {
return $html;
}

$html = sprintf( '<span class="course-price-suffix">%s</span>', $price_suffix_str );
} catch ( Throwable $e ) {
error_log( __METHOD__ . ': ' . $e->getMessage() );
}

return $html;
}

/**
* Render string to data content
*
Expand Down
44 changes: 27 additions & 17 deletions inc/admin/views/meta-boxes/course/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ public function metabox( $post_id ) {
}

public function general( $post_id ) {
$course = CourseModel::find( $post_id, true );
$repurchase_option_desc = sprintf( '1. %s', __( 'Reset course progress: The course progress and results of student will be removed.' ) );
$course = CourseModel::find( $post_id, true );
$repurchase_option_desc = sprintf( '1. %s', __( 'Reset course progress: The course progress and results of student will be removed.' ) );
$repurchase_option_desc .= '<br/>' . sprintf( '2. %s', __( 'Keep course progress: The course progress and results of student will remain.' ) );
$repurchase_option_desc .= '<br/>' . sprintf( '3. %s', __( 'Open popup: The student can decide whether their course progress will be reset with the confirm popup.' ) );
$max_students_desc = esc_html__( 'The maximum number of students that can join a course. Set 0 for unlimited.', 'learnpress' );
$max_students_desc = esc_html__( 'The maximum number of students that can join a course. Set 0 for unlimited.', 'learnpress' );
$max_students_desc .= '<br/>' . esc_html__( 'Not apply for case "No enroll requirement".', 'learnpress' );

$is_enable_allow_course_repurchase = false;
Expand Down Expand Up @@ -165,7 +165,7 @@ public function general( $post_id ) {
),
'dependency' => [
'name' => '_lp_allow_course_repurchase',
'is_disable' => ! $is_enable_allow_course_repurchase
'is_disable' => ! $is_enable_allow_course_repurchase,
],
//'show' => array( '_lp_allow_course_repurchase', '=', 'yes' ), // use 'show' or 'hide'
)
Expand Down Expand Up @@ -264,7 +264,7 @@ public function tab_offline( $post_id ): array {
return apply_filters(
'lp/course/meta-box/fields/offline',
array(
CoursePostModel::META_KEY_OFFLINE_COURSE => new LP_Meta_Box_Checkbox_Field(
CoursePostModel::META_KEY_OFFLINE_COURSE => new LP_Meta_Box_Checkbox_Field(
esc_html__( 'Enable offline course', 'learnpress' ),
esc_html__(
'When you enable the offline course feature, the system will disable certain online course functions, such as curriculum, finish button, re-take course, block content, repurchase. After checking the checkbox, make sure to click the "Update" button to apply the changes successfully.',
Expand All @@ -284,30 +284,30 @@ public function tab_offline( $post_id ): array {
),
'dependency' => [
'name' => '_lp_offline_course',
'is_disable' => ! $is_offline_course
'is_disable' => ! $is_offline_course,
],
]
),
CoursePostModel::META_KEY_DELIVER => new LP_Meta_Box_Select_Field(
CoursePostModel::META_KEY_DELIVER => new LP_Meta_Box_Select_Field(
esc_html__( 'Delivery Type', 'learnpress' ),
esc_html__( 'How your content is conveyed to students.', 'learnpress' ),
'private_1_1',
[
'options' => Config::instance()->get( 'course-deliver-type' ),
'dependency' => [
'name' => '_lp_offline_course',
'is_disable' => ! $is_offline_course
'is_disable' => ! $is_offline_course,
],
]
),
CoursePostModel::META_KEY_ADDRESS => new LP_Meta_Box_Text_Field(
CoursePostModel::META_KEY_ADDRESS => new LP_Meta_Box_Text_Field(
esc_html__( 'Address', 'learnpress' ),
esc_html__( 'You can enter the physical address of your class or specify the meeting method (e.g., Zoom, Google Meet, etc.).', 'learnpress' ),
'',
[
'dependency' => [
'name' => '_lp_offline_course',
'is_disable' => ! $is_offline_course
'is_disable' => ! $is_offline_course,
],
]
),
Expand Down Expand Up @@ -347,11 +347,11 @@ public function lp_price( $post_id ): array {
'min' => '0',
'step' => '0.01',
),
'style' => 'width: 70px;',
'style' => 'width: 100px;',
'class' => 'lp_meta_box_regular_price',
'dependency' => [
'name' => '_lp_no_required_enroll',
'is_disable' => $is_enable_no_required_enroll
'is_disable' => $is_enable_no_required_enroll,
],
)
),
Expand All @@ -365,11 +365,11 @@ public function lp_price( $post_id ): array {
'min' => '0',
'step' => '0.01',
),
'style' => 'width: 70px;',
'style' => 'width: 100px;',
'class' => 'lp_meta_box_sale_price',
'dependency' => [
'name' => '_lp_no_required_enroll',
'is_disable' => $is_enable_no_required_enroll
'is_disable' => $is_enable_no_required_enroll,
],
)
),
Expand All @@ -382,7 +382,7 @@ public function lp_price( $post_id ): array {
'placeholder' => _x( 'From&hellip;', 'placeholder', 'learnpress' ),
'dependency' => [
'name' => '_lp_no_required_enroll',
'is_disable' => $is_enable_no_required_enroll
'is_disable' => $is_enable_no_required_enroll,
],
)
),
Expand All @@ -396,10 +396,20 @@ public function lp_price( $post_id ): array {
'cancel' => true,
'dependency' => [
'name' => '_lp_no_required_enroll',
'is_disable' => $is_enable_no_required_enroll
'is_disable' => $is_enable_no_required_enroll,
],
)
),
'_lp_price_prefix' => new LP_Meta_Box_Text_Field(
esc_html__( 'Price prefix', 'learnpress' ),
esc_html__( 'Show additional information placed before the price such as: Only, From, Up to...', 'learnpress' ),
''
),
'_lp_price_suffix' => new LP_Meta_Box_Text_Field(
esc_html__( 'Price Suffix', 'learnpress' ),
esc_html__( 'Show additional information placed after the price such as: Included Tax, Per Hour, (Per Week)...', 'learnpress' ),
''
),
'_lp_no_required_enroll' => new LP_Meta_Box_Checkbox_Field(
esc_html__( 'There is no enrollment requirement', 'learnpress' ),
esc_html__( 'Students can see the content of all course items and take the quiz without logging in.', 'learnpress' ),
Expand Down Expand Up @@ -625,7 +635,7 @@ public function output( $post ) {
?>
<?php if ( isset( $tab_content['content'] ) ) { ?>
<div id="<?php echo esc_attr( $tab_content['target'] ); ?>"
class="lp-meta-box-course-panels">
class="lp-meta-box-course-panels">
<?php
do_action( 'learnpress/course-settings/before-' . $key );

Expand Down
23 changes: 16 additions & 7 deletions inc/course/abstract-course.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @version 4.0.0
*/

use LearnPress\Models\CourseModel;
use LearnPress\TemplateHooks\Course\SingleCourseTemplate;
use LearnPress\TemplateHooks\Instructor\SingleInstructorTemplate;

defined( 'ABSPATH' ) || exit();
Expand Down Expand Up @@ -449,7 +451,7 @@ public function get_viewing_item() {
*
* @return int
*/
public function get_fake_students() : int {
public function get_fake_students(): int {
return absint( $this->get_data( 'fake_students', 0 ) );
}

Expand Down Expand Up @@ -658,7 +660,7 @@ public function get_price() {
*
* @author tungnx
* @since 4.1.5
* @version 1.0.1
* @version 1.0.2
* @return string
*/
public function get_course_price_html(): string {
Expand All @@ -678,8 +680,16 @@ public function get_course_price_html(): string {
$price_html .= sprintf( '<span class="origin-price">%s</span>', $this->get_regular_price_html() );
}

$price_html .= sprintf( '<span class="price">%s</span>', learn_press_format_price( $this->get_price(), true ) );
$price_html = apply_filters( 'learn_press_course_price_html', $price_html, $this->has_sale_price(), $this->get_id() );
$price_html .= sprintf( '<span class="price">%s</span>', learn_press_format_price( $this->get_price(), true ) );
$course = CourseModel::find( $this->get_id(), true );
$singleCourseTemplate = SingleCourseTemplate::instance();
$price_html = sprintf(
'%1$s %2$s %3$s',
$singleCourseTemplate->html_price_prefix( $course ),
$price_html,
$singleCourseTemplate->html_price_suffix( $course )
);
$price_html = apply_filters( 'learn_press_course_price_html', $price_html, $this->has_sale_price(), $this->get_id() );
}

return sprintf( '<span class="course-item-price">%s</span>', $price_html );
Expand Down Expand Up @@ -1203,7 +1213,7 @@ public function get_item_nav( $current_item = false, $viewable = false ) {
$pos_tmp = $pos;

while ( $pos_tmp < $max ) {
$pos_tmp ++;
++$pos_tmp;

if ( ! $viewable ) {
$next_id = $item_ids[ $pos_tmp ];
Expand All @@ -1215,7 +1225,7 @@ public function get_item_nav( $current_item = false, $viewable = false ) {
$pos_tmp = $pos;

while ( $pos_tmp > 0 ) {
$pos_tmp --;
--$pos_tmp;

if ( ! $viewable ) {
$prev_id = $item_ids[ $pos_tmp ];
Expand Down Expand Up @@ -1266,7 +1276,6 @@ public function get_next_item_html( $args = null ) {
}

public function get_prev_item_html( $args = null ) {

}

public function get_preview_items() {
Expand Down

0 comments on commit 48653a6

Please sign in to comment.