WC_Shipping_Legacy_Flat_Rate::calculate_extra_shipping()
Deprecated from version 2.4.0
Additional rates defined like this:
Option Name | Additional Cost [+- Percents%] | Per Cost Type (order, class, or item).. It is no longer supported and can be removed in future releases. It is recommended to replace this function with the same one.
Adds extra calculated flat rates.
Method of the class: WC_Shipping_Legacy_Flat_Rate{}
No Hooks.
Return
null
. Nothing (null).
Usage
$WC_Shipping_Legacy_Flat_Rate = new WC_Shipping_Legacy_Flat_Rate(); $WC_Shipping_Legacy_Flat_Rate->calculate_extra_shipping( $method, $rate );
- $method(null) (required)
- Deprecated.
- $rate(array) (required)
- Rate information.
Changelog
Deprecated since | 2.4.0 |
Option Name | Additional Cost [+- Percents%] | Per Cost Type (order, class, or item).
WC_Shipping_Legacy_Flat_Rate::calculate_extra_shipping() WC Shipping Legacy Flat Rate::calculate extra shipping code WC 9.7.1
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 ); } } }