• 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_sanitize_amount() – Sanitize Amount

You appear to be a bot. Output may be restricted

Description

Sanitize Amount

Returns a sanitized amount by stripping out thousands separators.

Usage

$string = edd_sanitize_amount( $amount );

Parameters

$amount
( string ) required – Price amount to format

Returns

string $amount Newly sanitized amount

Source

File name: easy-digital-downloads/includes/formatting.php
Lines:

1 to 48 of 48
function edd_sanitize_amount( $amount ) {
  $is_negative   = false;
  $thousands_sep = edd_get_option( 'thousands_separator', ',' );
  $decimal_sep   = edd_get_option( 'decimal_separator', '.' );

  // Sanitize the amount
  if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) {
    if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
      $amount = str_replace( $thousands_sep, '', $amount );
    } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) {
      $amount = str_replace( '.', '', $amount );
    }

    $amount = str_replace( $decimal_sep, '.', $amount );
  } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
    $amount = str_replace( $thousands_sep, '', $amount );
  }

  if( $amount < 0 ) {
    $is_negative = true;
  }

  $amount   = preg_replace( '/[^0-9\.]/', '', $amount );

  
/**
 * Filter number of decimals to use for prices
 *
 * @since unknown
 *
 * @param int $number Number of decimals
 * @param int|string $amount Price
 */
  $decimals = apply_filters( 'edd_sanitize_amount_decimals', 2, $amount );
  $amount   = number_format( (double) $amount, $decimals, '.', '' );

  if( $is_negative ) {
    $amount *= -1;
  }

  
/**
 * Filter the sanitized price before returning
 *
 * @since unknown
 *
 * @param string $amount Price
 */
  return apply_filters( 'edd_sanitize_amount', $amount );
}
 

 View on GitHub View on Trac

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

Primary Sidebar

Information

Function name: edd_sanitize_amount
Plugin ref: Easy Digital Downloads
Version: 2.10.1
Sourcefile: includes/formatting.php
File ref: includes/formatting.php
Deprecated?: No
API Letters: A,E,S

Footer

Easy Digital Downloads a2z
Easy Digital Downloads a2z
Easy Digital Downloads a2z
WordPress 5.7
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