Account Settings

Winkelwagen

De winkelwagen is nog leeg

Website Settings

Dondere modus
Hoog contrast
Font grootte
Lees pagina-inhoud
Afdrukken
Realtime
  • Datum: 19-02-2026
  • Week: 08
  • Weer:
  • Seizoen: Winter

WooCommerce: Disable Shipping Rate if Cart has Shipping Class

Bekijk website

Omschrijving

/**
* @snippet Disable Free Shipping if Cart has Shipping Class (WooCommerce 2.6+)
* @how-to Watch tutorial @ https://businessbloomer.com/?p=19055
* @sourcecode https://businessbloomer.com/?p=19960
* @author Rodolfo Melogli
* @testedwith WooCommerce 2.6.1
*/

add_filter( ‘woocommerce_package_rates’, ‘businessbloomer_hide_free_shipping_for_shipping_class’, 10, 2 );

function businessbloomer_hide_free_shipping_for_shipping_class( $rates, $package ) {

//Shipping class D
$shipping_class_target = 431;
$in_cart = false;
foreach( WC()->cart->cart_contents as $key => $values ) {
if( $values[ ‘data’ ]->get_shipping_class_id() == $shipping_class_target ) {
$in_cart = true;
break;
}
}
if( $in_cart ) {
unset( $rates[‘free_shipping:8’] );
unset( $rates[‘flat_rate:13’] );
unset( $rates[‘free_shipping:14’] );
}

// Shipping class C
$shipping_class_target = 292;
$in_cart = false;
foreach( WC()->cart->cart_contents as $key => $values ) {
if( $values[ ‘data’ ]->get_shipping_class_id() == $shipping_class_target ) {
$in_cart = true;
break;
}
}
if( $in_cart ) {
if(isset($rates[‘flat_rate:13’]))
unset( $rates[‘flat_rate:13’] );

if(isset($rates[‘free_shipping:14’]))
unset( $rates[‘free_shipping:14’] );
}

return $rates;
}

Snippet

FieldValue
Snippet Status
Snippet Description
Snippet Type Code
Snippet URL
Snippet Content
Snippet Content CSS
Snippet Content HTML
Snippet Content JS
Snippet Content PHP
Particle Snippet in Software
Particle Snippet in Boilerplate

Relations

ItemType

Pointing items

ItemTypeCategoryTags

Geef een reactie

Je e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *

Home