if ( is_string( $currency ) ) {
$currencies = wpforms_get_currencies();
$currency_code = strtoupper( $currency );
$currency = isset( $currencies[ $currency_code ] ) ? $currencies[ $currency_code ] : [];
* @param int $decimals Default number of decimals.
* @param array|string $currency Currency data we are getting decimals for.
return (int) apply_filters(
'wpforms_get_currency_decimals',
isset( $currency['decimals'] ) ? $currency['decimals'] : 2,
* If the currency not available anymore 'USD' used as default.
function wpforms_get_currency() {
$currency = wpforms_setting( 'currency' );
$currencies = wpforms_get_currencies();
* @param string $currency Payments currency.
* @param array $currencies Available currencies.
isset( $currencies[ $currency ] ) ? $currency : 'USD',
* Return recognized payment field types.
function wpforms_payment_fields() {
* Filters the recognized payment field types.
* @param array $fields Payment field types.
return (array) apply_filters(
'wpforms_payment_fields',
[ 'payment-single', 'payment-multiple', 'payment-checkbox', 'payment-select' ]
* Check if form or entry contains payment.
* @param string $type Either 'entry' or 'form'.
* @param array $data List of form fields.
function wpforms_has_payment( $type = 'entry', $data = [] ) {
$payment_fields = wpforms_payment_fields();
if ( ! empty( $data['fields'] ) ) {
foreach ( $data as $field ) {
if ( isset( $field['type'] ) && in_array( $field['type'], $payment_fields, true ) ) {
// For entries, only return true if the payment field has an amount.
! empty( $field['amount'] ) &&
! empty( wpforms_sanitize_amount( $field['amount'] ) )
* Check to see if a form has an active payment gateway configured.
* @param array $form_data Form data and settings.
function wpforms_has_payment_gateway( $form_data ) {
// PayPal Standard check.
if ( ! empty( $form_data['payments']['paypal_standard']['enable'] ) ) {
if ( ! empty( $form_data['payments']['stripe']['enable'] ) ) {
* Allow modifying whether a form has an active payment gateway.
* @param bool $result True if a form has an active payment gateway.
* @param array $form_data Form data and settings.
return (bool) apply_filters( 'wpforms_has_payment_gateway', false, $form_data );
* Get payment total amount from entry.
* @since 1.8.2.2 Added PHP max() function before returning a total.
* @param array $fields List of fields.
function wpforms_get_total_payment( $fields ) {
$fields = wpforms_get_payment_items( $fields );
if ( empty( $fields ) ) {
foreach ( $fields as $field ) {
// Skip the field hidden by conditional logic.
if ( isset( $field['visible'] ) && $field['visible'] === false ) {
if ( empty( $field['amount'] ) ) {
$amount = wpforms_sanitize_amount( $field['amount'] );
if ( ! empty( $field['quantity'] ) ) {
$amount *= (int) $field['quantity'];
$total = max( 0, $total );
return wpforms_sanitize_amount( $total );
* Get payment fields in an entry.
* @param array $fields List of fields.
* @return array|bool False if no fields provided, otherwise array.
function wpforms_get_payment_items( $fields = [] ) {
if ( empty( $fields ) ) {
$payment_fields = wpforms_payment_fields();
foreach ( $fields as $id => $field ) {
empty( $field['type'] ) ||
empty( $field['amount'] ) ||
! in_array( $field['type'], $payment_fields, true ) ||
empty( wpforms_sanitize_amount( $field['amount'] ) ) ||
( isset( $field['quantity'] ) && ! $field['quantity'] )
// Remove all non-payment fields as well as payment fields with no amount or empty quantity.
* Determine if field has quantity enabled.
* @param array $field Field data.
* @param array $form_data Form data.
function wpforms_payment_has_quantity( array $field, array $form_data ): bool {
if ( ! isset( $field['id'] ) ) {
if ( isset( $field['quantity'] ) ) {
$field_settings = $form_data['fields'][ $field['id'] ] ?? [];
if ( empty( $field_settings['enable_quantity'] ) ) {
// Quantity is available only for `single` format of the Single payment field.
if ( $field_settings['type'] === 'payment-single' && $field_settings['format'] !== 'single' ) {
// Otherwise return true.
// It covers the Dropdown Items field (and others where the quantity will be supported).
* Formatted payment field value with quantity.
* @param array $field Field data.
function wpforms_payment_format_quantity( array $field ): string {
if ( empty( $field['value'] ) ) {
return sprintf( /* translators: %1$s - payment amount; %2$d - payment quantity. */
esc_html__( '%1$s × %2$d', 'wpforms-lite' ),
* Get the multiplier for a given currency based on its decimal places.
* This function returns a scaling factor used to convert between
* the smallest currency unit (e.g., cents for USD) and the standard
* - USD (2 decimal places) → returns 100
* - JPY (0 decimal places) → returns 1
* @param string $currency Currency.
function wpforms_get_currency_multiplier( string $currency = '' ): int {
$currency = wpforms_get_currency();
return (int) str_pad( 1, wpforms_get_currency_decimals( strtolower( $currency ) ) + 1, 0, STR_PAD_RIGHT );