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 11.3.0
public function fee( $atts ) {
$atts = shortcode_atts(
array(
'percent' => '',
'min_fee' => '',
'max_fee' => '',
),
$atts,
'fee'
);
// Merchants type these in the store's number format, so read its decimal separator as a dot.
$atts = array_map(
function ( $value ) {
return str_replace( wc_get_price_decimal_separator(), '.', (string) $value );
},
$atts
);
$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;
}