Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. add_filter('woocommerce_get_price_html', 'elex_display_striked_out_price_for_variable', 200, 2);
  2. function elex_display_striked_out_price_for_variable($price='', $product)
  3. {
  4. $reg_price = '';
  5. if($product->is_type( 'variable' ))
  6. {
  7. $variations = $product->get_children();
  8. $reg_prices = array();
  9. $sale_prices = array();
  10. foreach ($variations as $value) {
  11. $single_variation=new WC_Product_Variation($value);
  12. array_push($reg_prices, $single_variation->get_regular_price());
  13. array_push($sale_prices, $single_variation->get_price());
  14. }
  15. sort($reg_prices);
  16. sort($sale_prices);
  17. $min_price = $reg_prices[0];
  18. $max_price = $reg_prices[count($reg_prices)-1];
  19. if($min_price == $max_price)
  20. {
  21. $reg_price = wc_price($min_price);
  22. }
  23. else
  24. {
  25. $reg_price = wc_format_price_range($min_price, $max_price);
  26. }
  27. $min_price = $sale_prices[0];
  28. $max_price = $sale_prices[count($sale_prices)-1];
  29. if($min_price == $max_price)
  30. {
  31. $sale_price = wc_price($min_price);
  32. }
  33. else
  34. {
  35. $sale_price = wc_format_price_range($min_price, $max_price);
  36. }
  37. return wc_format_sale_price($reg_price, $sale_price);
  38. }
  39. return $price;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement