Skip to content

Feature/return user discount #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions inc/admin/settings/class-lp-settings-general.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ public function get_settings( $section = '', $tab = '' ) {
'type' => 'heading',
'desc' => __( 'Setting up your currency unit and its formatting.', 'learnpress' )
),
array(
'title' => __( 'Returning Customer Discount', 'learnpress' ),
'id' => 'returning_customer_discount',
'type' => 'number',
'clone' => false,
'desc' => __( 'Set a percentage to discount the courses by if the its a returning customer (enter zero or leave blank for no discount)', 'learnpress' ),
'min' => 0,
'std' => 0
),
array(
'title' => __( 'Currency', 'learnpress' ),
'id' => 'currency',
Expand Down
10 changes: 9 additions & 1 deletion inc/course/abstract-course.php
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,15 @@ public function get_price() {
if ( ! $price /* || 'yes' != $this->get_data('payment') */ ) {
$price = 0;
} else {
if ( false !== ( $sale_price = $this->get_sale_price() ) ) {
$hasPaid = learn_press_get_current_user()->is_returning();
$maybe_discount = LP()->settings->get( 'returning_customer_discount');
if ($hasPaid && $maybe_discount > 0){
$price = floatval($price);
$price = $price - (($maybe_discount*$price)/100);
}
$price = floatval( $price );
$sale_price = $this->get_sale_price();
if ( is_numeric( $sale_price ) ) {
$price = $sale_price;
}
}
Expand Down
17 changes: 17 additions & 0 deletions inc/user/abstract-lp-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,23 @@ public function __get( $key ) {
return $return;
}

/**
*
* @return Bool
* Will return true or false depending on wheter the user is a
* returning customer or not
*/

public function is_returning($currentID){
$hasPaid = false;
$filter_status = LP_Request::get_string( 'filter-status' );
$query = $this->get_purchased_courses();
if(sizeof($query['items']) > 0){
$hasPaid = true;
}
return $hasPaid;
}

/**
* Check if a course is exists then return it's ID.
* Try to get it from global.
Expand Down