You appear to be a bot. Output may be restricted
Description
Adds a new Fee
Usage
$array = EDD_Fees::add_fee( $args );
Parameters
- $args
- ( array ) optional – Fee arguments
Returns
array The fees.
Source
File name: easy-digital-downloads/includes/class-edd-fees.php
Lines:
1 to 86 of 86
public function add_fee( $args = array() ) { // Backwards compatibility with pre 2.0 if ( func_num_args() > 1 ) { $args = func_get_args(); $amount = $args[0]; $label = isset( $args[1] ) ? $args[1] : ''; $id = isset( $args[2] ) ? $args[2] : ''; $type = 'fee'; $args = array( 'amount' => $amount, 'label' => $label, 'id' => $id, 'type' => $type, 'no_tax' => false, 'download_id' => 0, 'price_id' => NULL ); } else { $defaults = array( 'amount' => 0, 'label' => '', 'id' => '', 'no_tax' => false, 'type' => 'fee', 'download_id' => 0, 'price_id' => NULL ); $args = wp_parse_args( $args, $defaults ); if( $args['type'] != 'fee' && $args['type'] != 'item' ) { $args['type'] = 'fee'; } } // If the fee is for an "item" but we passed in a download id if( 'item' === $args['type'] && ! empty( $args['download_id'] ) ) { unset( $args['download_id'] ); unset( $args['price_id'] ); } if ( ! empty( $args['download_id'] ) ) { $options = isset( $args['price_id'] ) ? array( 'price_id' => $args['price_id'] ) : array(); if ( ! edd_item_in_cart( $args['download_id'], $options ) ) { return false; } } $fees = $this->get_fees( 'all' ); // Determine the key $key = empty( $args['id'] ) ? sanitize_key( $args['label'] ) : sanitize_key( $args['id'] ); // Remove the unneeded id key unset( $args['id'] ); // Sanitize the amount $args['amount'] = edd_sanitize_amount( $args['amount'] ); // Force the amount to have the proper number of decimal places. $args['amount'] = number_format( (float) $args['amount'], edd_currency_decimal_filter(), '.', '' ); // Force no_tax to true if the amount is negative if( $args['amount'] < 0 ) { $args['no_tax'] = true; } // Set the fee $fees[ $key ] = apply_filters( 'edd_fees_add_fee', $args, $this ); // Allow 3rd parties to process the fees before storing them in the session $fees = apply_filters( 'edd_fees_set_fees', $fees, $this ); // Update fees EDD()->session->set( 'edd_cart_fees', $fees ); do_action( 'edd_post_add_fee', $fees, $key, $args ); return $fees; }