WC_Shipping_Flat_Rate::fee
Work out fee (shortcode).
Method of the class: WC_Shipping_Flat_Rate{}
No Hooks.
Returns
String.
Usage
$WC_Shipping_Flat_Rate = new WC_Shipping_Flat_Rate(); $WC_Shipping_Flat_Rate->fee( $atts );
- $atts(array) (required)
- Attributes.
WC_Shipping_Flat_Rate::fee() WC Shipping Flat Rate::fee code WC 10.7.0
public function fee( $atts ) {
$atts = shortcode_atts(
array(
'percent' => '',
'min_fee' => '',
'max_fee' => '',
),
$atts,
'fee'
);
$calculated_fee = 0;
if ( $atts['percent'] ) {
$calculated_fee = $this->fee_cost * ( floatval( $atts['percent'] ) / 100 );
// Fix: Round to display decimals to prevent floating-point precision drift.
// @see https://github.com/woocommerce/woocommerce/issues/62692.
$calculated_fee = round( $calculated_fee, wc_get_price_decimals() );
}
if ( $atts['min_fee'] && $calculated_fee < $atts['min_fee'] ) {
$calculated_fee = $atts['min_fee'];
}
if ( $atts['max_fee'] && $calculated_fee > $atts['max_fee'] ) {
$calculated_fee = $atts['max_fee'];
}
return (string) $calculated_fee;
}