Warning: This method has been deprecated. Additional rates defined like this: Option Name | Additional Cost [+- Percents%] | Per Cost Type (order, class, or item) instead.

WC_Shipping_Legacy_Flat_Rate::calculate_extra_shipping( null $method, array $rate )

Adds extra calculated flat rates.


Description Description


Parameters Parameters

$method

(Required) Deprecated.

$rate

(Required) Rate information.


Top ↑

Source Source

File: includes/shipping/legacy-flat-rate/class-wc-shipping-legacy-flat-rate.php

	public function calculate_extra_shipping( $method, $rate ) {
		if ( $this->options ) {
			$options = array_filter( (array) explode( "\n", $this->options ) );

			foreach ( $options as $option ) {
				$this_option = array_map( 'trim', explode( WC_DELIMITER, $option ) );
				if ( count( $this_option ) !== 3 ) {
					continue;
				}
				$extra_rate          = $rate;
				$extra_rate['id']    = $this->id . ':' . urldecode( sanitize_title( $this_option[0] ) );
				$extra_rate['label'] = $this_option[0];
				$extra_cost          = $this->get_extra_cost( $this_option[1], $this_option[2], $rate['package'] );
				if ( is_array( $extra_rate['cost'] ) ) {
					$extra_rate['cost']['order'] = $extra_rate['cost']['order'] + $extra_cost;
				} else {
					$extra_rate['cost'] += $extra_cost;
				}

				$this->add_rate( $extra_rate );
			}
		}
	}

Top ↑

Changelog Changelog

Changelog
Version Description
2.4.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.