Combining Snippets
-
I have 2 snippets but only one of them is allowing to be activated at once. How can I combine them? I guess it will not allow me to use “function” twice. Pleas help! I know its an easy solution, just not sure what it is. Thank you in advance!
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_target = '1173'; // shipping class ID (to find it, see screenshot below) $in_cart = false; foreach ( WC()->cart->get_cart_contents() as $key => $values ) { if ( $values[ 'data' ]->get_shipping_class_id() == $shipping_class_target ) { $in_cart = true; break; } } if ( $in_cart ) { unset( $rates['local_pickup:45'] ); // shipping method with ID (to find it, see screenshot below) } return $rates; }
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_target = '1750'; // shipping class ID (to find it, see screenshot below) $in_cart = false; foreach ( WC()->cart->get_cart_contents() as $key => $values ) { if ( $values[ 'data' ]->get_shipping_class_id() == $shipping_class_target ) { $in_cart = true; break; } } if ( $in_cart ) { unset( $rates['flat_rate:41'] ); // shipping method with ID (to find it, see screenshot below) } return $rates; }
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Combining Snippets’ is closed to new replies.