kallovsky
Forum Replies Created
-
Forum: Plugins
In reply to: [WooReer] Flat rate for certain shipping classHey there,
I also had that issue and used as workaround a little function.
Create an own shipping class for WooReer and asign all WooReer shippable articles to that class. We use that shipping class as an indicator which articles are we dealing with
// parse cart articles for shipping classes 'your_custom_classname' and hide flat rate delivery in that case - vice versa hide the WooReer method in case the specified class was not found add_filter( 'woocommerce_package_rates', 'hide_shipping_when_class_is_in_cart', 100, 2 ); function hide_shipping_when_class_is_in_cart( $rates, $package ) { // Initialisation $remove_shipping_methods = array( 'flat_rate:5' ); // your shipping method id comes here ( find it's name by it's css class and add ':' between string and its id ) $shipping_classes = array( 'your_custom_class_name' ); // your WooReer class the id is eual to your slug: /wp-admin/admin.php?page=wc-settings&tab=shipping§ion=classes $class_exists = false; foreach( $package['contents'] as $cart_item ){ if( in_array( $cart_item['data']->get_shipping_class(), $shipping_classes ) ) { $class_exists = true; break; // Stop the loop } } if( $class_exists ){ // var_dump ($rates); foreach ($remove_shipping_methods as $shipping_method) { if ( isset ( $rates[$shipping_method] ) ) { unset( $rates[$shipping_method] ); } } }else{ if ( isset( $rates['wcsdm:7'] ) ) { // wcsdm:7 is the id for "WooReer" Plugins shipping method unset( $rates['wcsdm:7'] ); } } return $rates; }
Only thing you have to find out is the propper shipping method ID you want to disable. To do this maybe that articles helps (also see comment at the code section):
https://www.bolderelements.net/support/knowledgebase/finding-the-shipping-options-id/Of course you can change the behavior of the code to your needs. At example how to behave when two different types of items are in cart? In my case I’m just going to deliver the smaller package together with the larger mile-based package in case two different types of articles are merged up in cart.
Idea and source of the code:
https://stackoverflow.com/questions/49284009/disable-free-shipping-based-on-shipping-classes-in-woocommerceHope that helps :)!