Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Created June 16, 2015 11:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikejolley/67580b9e8b1c2ed1081f to your computer and use it in GitHub Desktop.
Save mikejolley/67580b9e8b1c2ed1081f to your computer and use it in GitHub Desktop.
add_action( 'woocommerce_flat_rate_shipping_add_rate', 'add_another_custom_flat_rate', 10, 2 );
function add_another_custom_flat_rate( $method, $rate ) {
$new_rate = $rate;
$new_rate['id'] .= ':' . 'custom_rate_name'; // Append a custom ID
$new_rate['label'] = 'Rushed Shipping'; // Rename to 'Rushed Shipping'
$new_rate['cost'] += 2; // Add $2 to the cost
// Add it to WC
$method->add_rate( $new_rate );
}
@ZAAAX
Copy link

ZAAAX commented Sep 23, 2015

Hi Mike,
I love your code. Suits my needs very well.
I also wanted to add another flat rate besides the "Rushed Shipping" rate you have in the add_action.

To do that, do I just add ......

add_action( 'woocommerce_flat_rate_shipping_add_rate', 'add_another_custom_flat_rate', 10, 2 );

function add_another_custom_flat_rate( $method, $rate ) {
$new_rate = $rate;
$new_rate['id'] .= ':' . 'custom_rate_name'; // Append a custom ID
$new_rate['label'] = 'Rushed Shipping' . 'Express Shipping'; // Rename to 'Rushed Shipping'
$new_rate['cost'] += 2 . 10; // Add $2 to the cost

// Add it to WC
$method->add_rate( $new_rate );

}

Am I anywhere near close?

@cadoo
Copy link

cadoo commented Jun 21, 2016

For international flat delivery rate you can use this:

add_action( 'woocommerce_international_delivery_shipping_add_rate', 'add_another_int_custom_flat_rate', 10, 2 );

function add_another_int_custom_flat_rate( $method, $rate ) {
    $new_rate          = $rate;
    $new_rate['id']    .= ':' . 'custom_rate_2_name'; // Append a custom ID
    $new_rate['label'] = 'Rushed International Shipping';
    $new_rate['cost']  += 13; // Add $13 to the cost

    // Add it to WC
    $method->add_rate( $new_rate );
}

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