Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. function mwe_calculate_discount( $total_discount, $cart ) {
  2.  
  3. //global $woocommerce;
  4. $num_products_required_for_discount = 4;
  5.  
  6. echo "<!-- Discount? -->";
  7.  
  8. $number_products = $cart->cart_contents_count;
  9. if ($number_products >= $num_products_required_for_discount) {
  10.  
  11. echo "<!-- QUALIFIES FOR DISCOUNT! -->";
  12.  
  13. for ($i = 0; $i < $number_products; $i++) {
  14.  
  15. // Get the reduced price of the product - TODO
  16.  
  17. // Calculate $product_discount
  18. $product_discount = 11.11; // TODO
  19.  
  20. // Add $product_discount to the $total_discount
  21. $total_discount += $product_discount;
  22. }
  23.  
  24. echo "<!-- Total discount: $total_discount -->";
  25.  
  26. }
  27. else {
  28.  
  29. echo "<!-- NO DISCOUNT -->";
  30.  
  31. }
  32.  
  33. return $total_discount;
  34.  
  35. }
  36. add_filter('woocommerce_cart_total_discount', 'mwe_calculate_discount', 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement