• 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::get_fees() – Retrieve all active fees

You appear to be a bot. Output may be restricted

Description

Retrieve all active fees

Usage

$array|bool = EDD_Fees::get_fees( $type, $download_id, $price_id );

Parameters

$type
( string ) optional default: fee – Fee type, "fee" or "item"
$download_id
( int ) optional – The download ID whose fees to retrieve
$price_id
( int ) optional – The variable price ID whose fees to retrieve

Returns

array|bool List of fees when available, false when there are no fees

Source

File name: easy-digital-downloads/includes/class-edd-fees.php
Lines:

1 to 66 of 66
  public function get_fees( $type = 'fee', $download_id = 0, $price_id = NULL ) {
    $fees = EDD()->session->get( 'edd_cart_fees' );

    if ( EDD()->cart->is_empty() ) {
      // We can only get item type fees when the cart is empty
      $type = 'item';
    }

    if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) {
      foreach ( $fees as $key => $fee ) {
        if ( ! empty( $fee['type'] ) && $type != $fee['type'] ) {
          unset( $fees[ $key ] );
        }
      }
    }

    if ( ! empty( $fees ) && ! empty( $download_id ) ) {
      // Remove fees that don't belong to the specified Download
      $applied_fees = array();
      foreach ( $fees as $key => $fee ) {

        if ( empty( $fee['download_id'] ) || (int) $download_id !== (int) $fee['download_id'] ) {
          unset( $fees[ $key ] );
        }

        $fee_hash   = md5( $fee['amount'] . $fee['label'] . $fee['type'] );

        if ( in_array( $fee_hash, $applied_fees ) ) {
          unset( $fees[ $key ] );
        }

        $applied_fees[] = $fee_hash;

      }
    }

    // Now that we've removed any fees that are for other Downloads, lets also remove any fees that don't match this price id
    if ( ! empty( $fees ) && ! empty( $download_id ) && ! is_null( $price_id ) ) {
      // Remove fees that don't belong to the specified Download AND Price ID
      foreach ( $fees as $key => $fee ) {
        if ( is_null( $fee['price_id'] ) ) {
          continue;
        }

        if ( (int) $price_id !== (int) $fee['price_id'] ){
          unset( $fees[ $key ] );
        }
      }
    }

    if ( ! empty( $fees ) ) {
      // Remove fees that belong to a specific download but are not in the cart
      foreach ( $fees as $key => $fee ) {
        if ( empty( $fee['download_id'] ) ) {
          continue;
        }

        if ( ! edd_item_in_cart( $fee['download_id'] ) ) {
          unset( $fees[ $key ] );
        }
      }
    }

    // Allow 3rd parties to process the fees before returning them
    return apply_filters( 'edd_fees_get_fees', ! empty( $fees ) ? $fees : array(), $this );
  }
 

 View on GitHub View on Trac

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

Primary Sidebar

Information

Function name: EDD_Fees::get_fees
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: E,F,G

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