Well I dug a little deeper and found that in the abstract WC_Product
class, there is the needs_shipping()
method:
/**
* Checks if a product needs shipping.
*
* @access public
* @return bool
*/
public function needs_shipping() {
return apply_filters( 'woocommerce_product_needs_shipping', $this->is_virtual() ? false : true, $this );
}
and it is filterable, which means we can override the need for shipping costs on any product we like. Assuming you have a shipping class with the slug: shipping-class
you can set any item with that class to not need shipping:
function wpa_123136_no_shipping( $needs_shipping, $product ){
if( $product->get_shipping_class() == 'free-shipping' ){
$needs_shipping = false;
}
return $needs_shipping;
}
add_filter('woocommerce_product_needs_shipping','wpa_123136_no_shipping', 10, 2 );
or if you have a price-point and don’t want to bother with the free shipping class:
function wpa_123136_no_shipping( $needs_shipping, $product ){
if( $product->get_price() < 200 ){
$needs_shipping = false;
}
return $needs_shipping;
}
add_filter('woocommerce_product_needs_shipping','wpa_123136_no_shipping', 10, 2 );