Skip to content

Commit 043be09

Browse files
committed
Used wc native helper to remove markup from wc_price()
1 parent 1ac7076 commit 043be09

4 files changed

Lines changed: 12 additions & 32 deletions

File tree

classes/Instructor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ public static function get_top_performing_courses_by_instructor( $instructor_id,
705705
* @since 4.0.0
706706
*
707707
* @param array $top_courses List of course objects returned from analytics.
708+
*
708709
* @return array Formatted top performing courses data.
709710
*/
710711
public static function format_instructor_top_performing_courses( $top_courses ) {
@@ -718,7 +719,7 @@ function ( $course ) {
718719
return array(
719720
'name' => $course->course_title,
720721
'url' => get_permalink( $course->course_id ),
721-
'revenue' => wp_kses_post( tutor_utils()->tutor_price( $course->total_revenue ?? 0 ) ),
722+
'revenue' => wp_kses_post( tutor_utils()->tutor_price( $course->total_revenue ?? 0, false ) ),
722723
'students' => $course->total_student ?? 0,
723724
);
724725
},

classes/Utils.php

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6257,27 +6257,27 @@ public function get_earning_statements( $user_id = 0, $filter_data = array() ) {
62576257
* Get the price format
62586258
*
62596259
* @since 1.1.2
6260-
* @since 4.0.0 Condition added for Paid Membership Pro Monetization.
6260+
* @since 4.0.0 Condition added for different monetizations and also added $html_markup for woocommece
62616261
*
62626262
* @param int $price price.
6263+
* @param bool $html_markup Whether to include HTML markup ( Only for woocommerce as it returns html markup ).
62636264
*
62646265
* @return int|string
62656266
*/
6266-
public function tutor_price( $price = 0 ) {
6267+
public function tutor_price( $price = 0, $html_markup = true ) {
62676268

6268-
$price_float = floatval( Input::sanitize( $price ) );
62696269
$monetize_by = $this->get_option( 'monetize_by' );
62706270

62716271
if ( Ecommerce::MONETIZE_BY === $monetize_by ) {
62726272
return tutor_get_formatted_price( $price );
6273-
} elseif ( 'wc' === $monetize_by ) {
6274-
return wc_price( $price );
6275-
} elseif ( 'edd' === $monetize_by ) {
6273+
} elseif ( function_exists( 'wc_price' ) && 'wc' === $monetize_by ) {
6274+
return wc_price( $price, array( 'in_span' => $html_markup ) );
6275+
} elseif ( function_exists( 'edd_currency_filter' ) && 'edd' === $monetize_by ) {
62766276
return edd_currency_filter( edd_format_amount( $price ) );
6277-
} elseif ( 'pmpro' === $monetize_by ) {
6278-
return pmpro_formatPrice( $price_float );
6277+
} elseif ( function_exists( 'pmpro_formatPrice' ) && 'pmpro' === $monetize_by ) {
6278+
return pmpro_formatPrice( floatval( $price ) );
62796279
} else {
6280-
return number_format_i18n( $price_float );
6280+
return number_format_i18n( floatval( $price ) );
62816281
}
62826282
}
62836283

@@ -10901,16 +10901,4 @@ public function get_script_locale_data( string $filename, string $locale = 'en_U
1090110901

1090210902
return null;
1090310903
}
10904-
10905-
/**
10906-
* Normalizes WooCommerce monetization output to plain text.
10907-
*
10908-
* @since 4.0.0
10909-
*
10910-
* @param string $value WooCommerce price HTML or encoded string.
10911-
* @return string Plain text monetary value.
10912-
*/
10913-
public function fix_wc_monetization_format( $value ): string {
10914-
return wp_strip_all_tags( wp_specialchars_decode( $value ) );
10915-
}
1091610904
}

templates/dashboard/instructor/home.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ function ( $carry, $section ) {
180180
'variation' => 'success',
181181
'title' => esc_html__( 'Total Earnings', 'tutor' ),
182182
'icon' => Icon::EARNING,
183-
'value' => wp_kses_post( tutor_utils()->tutor_price( $total_earnings ?? 0 ) ),
183+
'value' => wp_kses_post( tutor_utils()->tutor_price( $total_earnings ?? 0, false ) ),
184184
'hover_content' => $total_earnings_state_card_details,
185185
),
186186
array(
@@ -404,10 +404,6 @@ class="tutor-flex tutor-gap-5 tutor-z-positive"
404404
<?php foreach ( $stat_cards as $card ) : ?>
405405
<div class="tutor-flex-1">
406406
<?php
407-
// If from woo-commerce convert the monetization data to appropriate format.
408-
if ( 'wc' === tutor_utils()->get_option( 'monetize_by' ) ) {
409-
$card['value'] = tutor_utils()->fix_wc_monetization_format( $card['value'] );
410-
}
411407
tutor_load_template(
412408
'dashboard.instructor.analytics.stat-card',
413409
array(

templates/dashboard/instructor/home/top-performing-course-item.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
defined( 'ABSPATH' ) || exit;
1212

1313
use TUTOR\Icon;
14-
15-
// If from woo-commerce convert the monetization data to appropriate format.
16-
if ( 'wc' === tutor_utils()->get_option( 'monetize_by' ) ) {
17-
$item['revenue'] = tutor_utils()->fix_wc_monetization_format( $item['revenue'] );
18-
}
1914
?>
2015

2116
<div class="tutor-dashboard-home-course">

0 commit comments

Comments
 (0)