skip to Main Content

Create Second Shipping Price as Copy of First Option with Extra Fee

Several users of the Table Rate Shipping method for WooCommerce have requested the ability to offer a second shipping option to their customers without duplicating their entire table. In this scenario, the admin has setup a table of standard, parcel shipping rates. They want to offer a next day option that costs $5 in addition to the standard rate.

add_filter( 'woocommerce_package_rates', 'duplicate_standard_shipping_options', 10, 2 );
function duplicate_standard_shipping_options( $rates, $package ) {
	// Shipping Option ID to be duplicated
	$shipping_id = "betrs_shipping:1–1";

	// Shipping ID for new rate
	$new_shipping_id = "betrs_shipping:1–2";

	// Shipping title for new rate
	$new_shipping_title = "Shipping with Insurance";

	// Shipping Cost addition (adds $5 to standard rate's shipping cost)
	$add_shipping_cost = 5;

	foreach( $rates as $key => $value ) {

		if( $value->id == $shipping_id ) {
			$rates[ $new_shipping_id ] = new WC_Shipping_Rate(
				$new_shipping_id,
				$new_shipping_title,
				$value->cost + $add_shipping_cost,
				$value->taxes,
				$value->method_id
				);
		}
	}

	return $rates;
}
  • Was this article helpful ?
  • yesno
0 out of 0 visitors found this article helpful
Views: 51
Back To Top