Skip to content

Instantly share code, notes, and snippets.

@EvanHerman
Last active November 17, 2015 16:42
Show Gist options
  • Save EvanHerman/1c1766ecb4123dba2c96 to your computer and use it in GitHub Desktop.
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.
<?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;
}
?>
@EvanHerman
Copy link
Author

Results

results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment