Support » Plugin: WooCommerce » Shipping Automatically set?

Viewing 6 replies - 1 through 6 (of 6 total)
  • So if I get it right, you want to disable the paid option if the free shipping option is available? You can do this by filtering the available shipping methods:

    add_filter( 'woocommerce_available_shipping_methods', 'cj_woocommerce_available_shipping_methods' );
    
    function cj_woocommerce_available_shipping_methods( $available_methods ) {
    	if ( isset( $available_methods['free_shipping'] ) ) {
    		foreach ( $available_methods as $key => $value ) {
    			if ( 'free_shipping' != $key ) {
    				unset( $available_methods[ $key ] );
    			}
    		}
    	}	
    
    	return $available_methods;
    }

    This will deactivate all shipping methods, except for free, when free is available. Place this code in a plugin, or in your (child) themes functions.php.

    Cool! Thank you! exactly what I was looking for 🙂 It works …

    You rock, Coen. I needed this, too and it works perfectly. Thanks!

    Hi. Thats really great! 🙂

    But…how is it possible to let “international_delivery” and “local_pickup” active?

    Thanks very much in advance! 😉

    Best regards!

    Yeah you can narrow it down to pretty much all shipping methods, whatever you want. You just need to change the code to look for the right values.

    This code is based on making just free shipping available when it’s available, you will need another check to find when your two shipping methods should be available.

    In addition to Coen Jabobs and the question from Valex2013, this can, by changing the available methos in “unset($available_methods[‘local_delivery’]);”, see the difference:

    add_filter( 'woocommerce_available_shipping_methods', 'cj_woocommerce_available_shipping_methods' );
    
    	function cj_woocommerce_available_shipping_methods( $available_methods ) {
    	if ( isset( $available_methods['free_shipping'] ) ) {
    		foreach ( $available_methods as $key => $value ) {
    			if ( 'free_shipping' != $key ) {
    				unset( $available_methods[ 'local_delivery' ] );
    			}
    		}
    	}	
    
    	return $available_methods;
    	}
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Shipping Automatically set?’ is closed to new replies.