Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.