• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Easy Digital Downloads a2z

Easy Digital Downloads a2z

Easy Digital Downloads a2z

  • Home
  • Plugins
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / EDD_Fees::add_fee() – Adds a new Fee

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;
  }
 

 View on GitHub View on Trac

Published: 26th November 2019 | Last updated: 26th November 2019

Primary Sidebar

Information

Function name: EDD_Fees::add_fee
Class ref: EDD_Fees
Plugin ref: Easy Digital Downloads
Version: 2.9.26
Sourcefile: includes/class-edd-fees.php
File ref: includes/class-edd-fees.php
Deprecated?: No
API Letters: A,E,F

Footer

Easy Digital Downloads a2z
Easy Digital Downloads a2z
Easy Digital Downloads a2z
WordPress 5.6.2
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  edd.wp-a2z.org
© Copyright Easy Digital Downloads a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites