Advertisement
businessdad

Round prices to the closest 50 cents

Dec 5th, 2019
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. /**
  2.  * Rounds the prices of products and variations to the closest 50 cents.
  3.  *
  4.  * DISCLAIMER
  5.  * Aelia and any member of its staff are not responsible for any data loss or damage incurred
  6.  * when using the code, which you can use at your own risk.
  7.  *
  8.  * GPL DISCLAIMER
  9.  * Because this code program is free of charge, there is no warranty for it, to the extent permitted by applicable law.
  10.  * Except when otherwise stated in writing the copyright holders and/or other parties provide the program "as is"
  11.  * without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of
  12.  * merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program
  13.  * is with you. should the program prove defective, you assume the cost of all necessary servicing, repair or correction.
  14.  *
  15.  * Need a consultation, or assistance to customise this code? Find us on Codeable: https://aelia.co/hire_us
  16.  */
  17. function custom_round_product_price($price, $product) {
  18.   // The price may be not numeric, or an empty string. In such
  19.   // case, it should be left as it is (an empty string means "no price"),
  20.   // not "zero"
  21.   if(!is_numeric($price) || ($price === '')) {
  22.     return $price;
  23.   }
  24.  
  25.   // Round the price to the closest 50 cents
  26.   return round($price * 2, 0) / 2;
  27. }
  28.  
  29. add_filter('woocommerce_product_get_price', 'custom_round_product_price', 10, 2);
  30. add_filter('woocommerce_product_variation_get_price', 'custom_round_product_price', 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement