This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | |
} |
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
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
}
Am I anywhere near close?