Skip to content

Instantly share code, notes, and snippets.

@BFTrick
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

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

Select an option

Save BFTrick/34e8b82d068ac7e15886 to your computer and use it in GitHub Desktop.
Disable Freight Table Rate Shipping Costs for BR
<?php
/**
* Plugin Name: WooCommerce Disable Freight when UPS Rates are Present
* Plugin URI: https://gist.github.com/BFTrick/34e8b82d068ac7e15886
* Description: A simple plugin that disables the freight Table Rate Shipping methods when UPS rates are available. It leaves the Local Delivery TRS methods.
* 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 ) {
// first make sure this shipping method is a table rate method
if ( false !== strpos( $key, "table_rate" ) ) {
// now check if the method has the label Local Delivery
if ( ! is_numeric ( strpos( $value->label, "Local Delivery" ) ) ) {
// if not then remove it
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