Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function mwe_calculate_discount( $total_discount, $cart ) {
- //global $woocommerce;
- $num_products_required_for_discount = 4;
- echo "<!-- Discount? -->";
- $number_products = $cart->cart_contents_count;
- if ($number_products >= $num_products_required_for_discount) {
- echo "<!-- QUALIFIES FOR DISCOUNT! -->";
- for ($i = 0; $i < $number_products; $i++) {
- // Get the reduced price of the product - TODO
- // Calculate $product_discount
- $product_discount = 11.11; // TODO
- // Add $product_discount to the $total_discount
- $total_discount += $product_discount;
- }
- echo "<!-- Total discount: $total_discount -->";
- }
- else {
- echo "<!-- NO DISCOUNT -->";
- }
- return $total_discount;
- }
- add_filter('woocommerce_cart_total_discount', 'mwe_calculate_discount', 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement