Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1.  
  2.  
  3. function you_save_echo_product() {
  4.     global $product;
  5.  
  6.     // works for Simple and Variable type
  7.     $regular_price  = get_post_meta( $product->get_id(), '_regular_price', true ); // 36.32
  8.     $sale_price     = get_post_meta( $product->get_id(), '_sale_price', true ); // 24.99
  9.  
  10.     if( !empty($sale_price) ) {
  11.  
  12.         $saved_amount       = $regular_price - $sale_price;
  13.         $currency_symbol    = get_woocommerce_currency_symbol();
  14.  
  15.         $percentage = round( ( ( $regular_price - $sale_price ) / $regular_price ) * 100 );
  16.         ?>
  17.             <p id="saving_total_price">You Save: <span class="symbol"><?php echo $currency_symbol; ?></span> <span class="amount"><?php echo $saved_amount; ?></span>.00</p>                
  18.         <?php      
  19.     }
  20. }
  21. //add_action( 'woocommerce_single_product_summary', 'you_save_echo_product', 11 );
  22. add_filter('woocommerce_get_price_html', function($price,$product){
  23.     ob_start();
  24.     you_save_echo_product();
  25.     $save = ob_get_clean();
  26.     return $price.$save;
  27. },10,2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement