Support » Plugin: Woocommerce Role Pricing » Wish it could show normal price and discount price

Viewing 2 replies - 1 through 2 (of 2 total)
  • Using an example found on http://www.eggemplo.com/blog/display-the-original-and-discounted-price/ I changed some things in the plugin.

    I hope the original author does not mind……..

    Add this to your functions.php file. You can change the appearance in the line where it says $result = 'Was: <strike>' . $original_price . "</strike></br> Now: " . $price;

    add_filter( 'woocommerce_get_price_html', 'your_own_price_html', 100, 2 );
    
    function your_own_price_html( $price, $product ){
      $result = $price;
    
      if ( get_option( "wrp-baseprice", "regular" ) == "sale" ) {
        $price_key = '_price';
      } else {
        $price_key = '_regular_price';
      }
    
      if ( $product->product_type == 'variable' ) {
    
        $children = $product->get_children(true);
    
        $original_prices = array();
        $commission = 0;
        foreach ( $children as $child ) {
          $original_prices[] = get_post_meta( $child, $price_key, true );
          if ( $commission == 0 ) {
            $commission = WRP_Variations_Admin::get_commission( $product, $child );
          }
        }
    
        if ( $commission > 0 ) {
          $min_price = min( $original_prices );
          $max_price = max( $original_prices );
          $original_price = $min_price !== $max_price ? sprintf( _x( '%1$s–%2$s', 'Price range: from-to', 'woocommerce' ), wc_price( $min_price ), wc_price( $max_price ) ) : wc_price( $min_price );
        }
      } else {
        $commission = WooRolePricingLight::get_commission( $product );
        if ( $commission ) {
          $original_price = woocommerce_price(get_post_meta( $product->id, $price_key, true ));
        }
      }
    
      if ( $commission ) {
    	$result =  'Was: <strike>' . $original_price . "</strike></br> Now: " . $price;
      }
      return $result;
    }

    None of this code is mine and I am thanking the original author https://wordpress.org/plugins/woocommerce-role-pricing/developers/ for making this great plugin!

    Thread Starter tondosusanto

    (@tondosusanto)

    Hi Peter, thanks for your information but I’m not good enough in coding, I copied your script and paste it to my function.php but it didn’t work and it messed my home and shop page, only one product show with error :
    Fatal error: Class ‘WGP_Variations_Admin’ not found in /home/enagaler/public_html/wp-content/themes/mts_woocart/functions.php on line 1544

    I am using wordpress 4.6 with woocommerce 2.6.4 Woocommerce Role Pricing Light 2.4 and User Role Editor By Vladimir Garagulya

    I found function.php in /public_html/wp-content/themes/mts_woocart (am I right?)

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Wish it could show normal price and discount price’ is closed to new replies.