Last active
November 17, 2015 16:42
-
-
Save EvanHerman/1c1766ecb4123dba2c96 to your computer and use it in GitHub Desktop.
Remove default shipping methods from the dashboard (doesn't work to unset 'Flat Rate'). Great for cleaning up the shipping settings page and managing what shipping methods are available for site admins to manage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Remove unused shipping rates from the dashboard | |
* note: WC_Shipping_Flat_Rate does not work here | |
* Defaults: | |
* - WC_Shipping_Free_Shipping | |
* - WC_Shipping_International_Delivery | |
* - WC_Shipping_Local_Delivery | |
* - WC_Shipping_Local_Pickup | |
*/ | |
add_filter( 'woocommerce_shipping_methods', 'remove_unused_shipping_methods' ); | |
function remove_unused_shipping_methods( $methods ) { | |
// set the shipping methods you don't need | |
$remove_shipping_methods = array( | |
'WC_Shipping_Free_Shipping', | |
'WC_Shipping_International_Delivery', | |
'WC_Shipping_Local_Delivery', | |
'WC_Shipping_Local_Pickup', | |
); | |
// loop over the methods, and unset them | |
if( ! empty( $remove_shipping_methods ) ) { | |
foreach( $remove_shipping_methods as $shipping_method ) { | |
$position = array_search( $shipping_method, $methods ); | |
if( $position ) { | |
unset( $methods[ $position ] ); | |
// reset the array/keys | |
$methods = array_values( $methods ); | |
} | |
} | |
} | |
return $methods; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results