We want to give a discount based on the shipping cost to our customers (50% of the shipping cost).
Below is the code to manipulate the discount, it's okay but I can't get the shipping cost. Tried php $current_shipping_cost = WC()->cart->get_cart_shipping_total();
but it does not return the correct value.
Is there a way to do this?
function woocommerce_coupon_get_discount_amount($discount, $discounting_amount, $cart_item, $single, $coupon) {
if ($coupon->code == 'custom'){
/*It is needed to know the shipping cost to calculate the discount.
$current_shipping_cost = WC()->cart->get_cart_shipping_total();
echo $current_shipping_cost; is not returning the correct value.
*/
return $discount;
}
}
//add hook to coupon amount hook
add_filter('woocommerce_coupon_get_discount_amount', 'woocommerce_coupon_get_discount_amount', 100, 5);