-3

Shipping discount.

this there away to offer 50% discount on woocommerce shipping when you have 3 or more items in the cart?

eg

product 1

user3408291
  • 39
  • 1
  • 2
  • 9

1 Answers1

0

This is the answer to my question.

It will get the content count of the cart and discount it based on number items in there:

add_action('woocommerce_cart_calculate_fees','woocommerce_discount_for_shipping');

function woocommerce_discount_for_shipping() {
  global $woocommerce; 
  if ($woocommerce->cart->get_cart_contents_count() > 2) {
    $discount_cart = $cart->discount_cart;
    $shipping_including_tax = $woocommerce->cart->shipping_total + $woocommerce->cart->shipping_tax_total;
    $percentage = 0.4; // 0.5 =50% 0.4 =40%
    $discount = $shipping_including_tax * $percentage;
    //var_dump($discount);
    $woocommerce->cart->add_fee('Shipping Discount:', -$discount, false);
  }
}

Add this to your themes child function.php

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
user3408291
  • 39
  • 1
  • 2
  • 9