Skip to content

Instantly share code, notes, and snippets.

@EvanHerman
Last active October 3, 2015 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EvanHerman/177cffb2ff6ab757fd53 to your computer and use it in GitHub Desktop.
Save EvanHerman/177cffb2ff6ab757fd53 to your computer and use it in GitHub Desktop.
Exclude shipping costs from certain products (by product ID )
<?php
function yikes_woocommerce_free_shipping( $is_available ) {
global $woocommerce;
// set the product ids that are eligible
$eligible = array( '360' );
// get cart contents
$cart_items = $woocommerce->cart->get_cart();
// loop through the items looking for one in the eligible array
foreach ( $cart_items as $key => $item ) {
if( in_array( $item['product_id'], $eligible ) ) {
return true;
}
}
// nothing found return the default value
return $is_available;
}
add_filter( 'woocommerce_shipping_free_shipping_is_available', 'yikes_woocommerce_free_shipping', 20 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment