Skip to content

Instantly share code, notes, and snippets.

@jasperf
Forked from mikejolley/functions.php
Created February 12, 2021 08:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jasperf/038b20794c0fb4f05ceaf1a31c8284c5 to your computer and use it in GitHub Desktop.
woocommerce_flat_rate_shipping_add_rate example for theme functions.php
<?php
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'] .= ':' . 'next_day'; // Append a custom ID
$new_rate['label'] = 'Next Day'; // Rename to 'Rushed Shipping'
$new_rate['cost'] += 2; // Add $2 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