Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save BFTrick/ab2841ca0daaca413379 to your computer and use it in GitHub Desktop.

Select an option

Save BFTrick/ab2841ca0daaca413379 to your computer and use it in GitHub Desktop.
WooCommerce Disable Table Rate Shipping when UPS Rates are Present
<?php
/**
* Plugin Name: WooCommerce Disable Table Rate Shipping when UPS Rates are Present
* Plugin URI: https://gist.github.com/BFTrick/ab2841ca0daaca413379/
* Description: A simple plugin that disables the Table Rate Shipping methods when UPS rates are available.
* Author: Patrick Rauland
* Author URI: http://patrickrauland.com/
* Version: 1.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
function patricks_disable_freight( $rates, $package ) {
// check if at least one UPS rate is returned
if ( isset( $rates['ups:01'] ) ) {
// loop trough available rates and unset any table rate
foreach ( $rates as $key => $value ) {
if ( false !== strpos( $key, "table_rate" ) ) {
unset( $rates[$key] );
}
}
}
return $rates;
}
add_filter( 'woocommerce_package_rates', 'patricks_disable_freight', 50, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment