WC_Shipping_Legacy_Flat_Rate::calculate_extra_shipping()publicWC 1.0

Устарела с версии 2.4.0 Additional rates defined like this: Option Name | Additional Cost [+- Percents%] | Per Cost Type (order, class, or item).. Больше не поддерживается и может быть удалена. Рекомендуется заменить эту функцию на аналог.

Adds extra calculated flat rates.

Метод класса: WC_Shipping_Legacy_Flat_Rate{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$WC_Shipping_Legacy_Flat_Rate = new WC_Shipping_Legacy_Flat_Rate();
$WC_Shipping_Legacy_Flat_Rate->calculate_extra_shipping( $method, $rate );
$method(null) (обязательный)
Deprecated.
$rate(массив) (обязательный)
Rate information.

Список изменений

Устарела с 2.4.0
Additional rates defined like this:
Option Name | Additional Cost [+- Percents%] | Per Cost Type (order, class, or item).

Код WC_Shipping_Legacy_Flat_Rate::calculate_extra_shipping() WC 8.7.0

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 );
		}
	}
}