Skip to content

Instantly share code, notes, and snippets.

@bryceadams
Created February 18, 2015 02:52
Show Gist options
  • Save bryceadams/221d9703f8fc0842887e to your computer and use it in GitHub Desktop.
Save bryceadams/221d9703f8fc0842887e to your computer and use it in GitHub Desktop.
WooCommerce no shipping available for certain products
function wcs_no_specific_shipping( $rates ) {
global $woocommerce;
// set the product ids that are eligible
$eligible = array( '963' );
// 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 false;
}
}
// nothing found return the default value
return $rates;
}
add_filter( 'woocommerce_package_rates', 'wcs_no_specific_shipping', 20 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment