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.
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 );
}
}
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.4.0 | Introduced. |