diff --git a/inc/admin/settings/class-lp-settings-general.php b/inc/admin/settings/class-lp-settings-general.php index 1ffe3055a..397cf81f5 100644 --- a/inc/admin/settings/class-lp-settings-general.php +++ b/inc/admin/settings/class-lp-settings-general.php @@ -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', diff --git a/inc/course/abstract-course.php b/inc/course/abstract-course.php index 3fd263231..04415973a 100644 --- a/inc/course/abstract-course.php +++ b/inc/course/abstract-course.php @@ -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; } } diff --git a/inc/user/abstract-lp-user.php b/inc/user/abstract-lp-user.php index b92399ff9..b27c4da76 100644 --- a/inc/user/abstract-lp-user.php +++ b/inc/user/abstract-lp-user.php @@ -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.