Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save BFTrick/7340580 to your computer and use it in GitHub Desktop.
Save BFTrick/7340580 to your computer and use it in GitHub Desktop.
Disable Free Shipping on a product by product basis in WooCommerce. Used in this post: http://speakinginbytes.com/2013/11/disable-free-shipping-woocommerce/
<?php
/**
* Disable free shipping for select products
*
* @param bool $is_available
*/
function my_free_shipping( $is_available ) {
global $woocommerce;
// set the product ids that are ineligible
$ineligible = array( '14009', '14031' );
// get cart contents
$cart_items = $woocommerce->cart->get_cart();
// loop through the items looking for one in the ineligible array
foreach ( $cart_items as $key => $item ) {
if( in_array( $item['product_id'], $ineligible ) ) {
return false;
}
}
// nothing found return the default value
return $is_available;
}
add_filter( 'woocommerce_shipping_free_shipping_is_available', 'my_free_shipping', 20 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment