Question

I have a condition where I want to make shipping price zero. Is there any predefined function for that? like we have a predefined function for making the cart empty,

$woocommerce->cart->empty_cart(); 

Similarly is there any function to make shipping price zero?

Was it helpful?

Solution

As per the official documentation:

If free shipping is enabled customers will have access to free shipping on their orders. You can however specify a few conditions they must meet to be granted free shipping such as;

  • Minimum order amount
  • Coupon (Users will need to enter a valid free shipping coupon code to use this method. If a coupon is used, the minimum order amount will be ignored)
  • You can also choose specific countries to which free shipping is allowed.

Further, the free shipping method has an is_available function which can be hooked into:

return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', $is_available );

This means you can use add_filter() on woocommerce_shipping_free_shipping_is_available and return true or false.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top