bbdev

Learndash - Course price

May 10th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.27 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Return a formatted price of the given course, with currency prefix.
  4.  * It will return 'Free' for courses with no price.
  5.  *
  6.  * @param int $post_id
  7.  * @return string
  8.  */
  9. function bboss_learndash_course_price( $post_id ){
  10.     $options             = get_option( 'sfwd_cpt_options' );
  11.     $currency            = null;
  12.  
  13.     if ( !is_null( $options ) ) {
  14.         if ( isset( $options[ 'modules' ] ) && isset( $options[ 'modules' ][ 'sfwd-courses_options' ] ) && isset( $options[ 'modules' ][ 'sfwd-courses_options' ][ 'sfwd-courses_paypal_currency' ] ) )
  15.             $currency = $options[ 'modules' ][ 'sfwd-courses_options' ][ 'sfwd-courses_paypal_currency' ];
  16.     }
  17.  
  18.     if ( is_null( $currency ) ) {
  19.         $currency = 'USD';
  20.     }
  21.  
  22.     $course_options  = get_post_meta( $post_id, "_sfwd-courses", true );
  23.     $price           = $course_options && isset( $course_options[ 'sfwd-courses_course_price' ] ) ? $course_options[ 'sfwd-courses_course_price' ] : __( 'Free', 'boss-learndash' );
  24.  
  25.     if ( $price == '' ) {
  26.         $price .= __( 'Free', 'boss-learndash' );
  27.     }
  28.  
  29.     if ( is_numeric( $price ) ) {
  30.         if ( $currency == 'USD' ) {
  31.             $price = '$' . $price;
  32.         } else {
  33.             $price .= ' ' . $currency;
  34.         }
  35.     }
  36.    
  37.     return $price;
  38. }
Add Comment
Please, Sign In to add comment