• Resolved fcis999

    (@fcis999)


    I made a form where I want to allow users to pay using either USD or EUR, so I made a dropdown list having the two currencies to allow the user to chose the payment currency and then created a calculation field which will set the value depending on the currency choses. Now for stripe field the value will be set as the calculation field that was set but the problem the currency won’t change, so I wonder how I can change the currency of stripe depending on the selection of the currency that the user made? thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Zafer – WPMU DEV Support

    (@wpmudevsupport15)

    Hi @fcis999,

    I hope you are doing well today!

    You can try to use the following code snippet as mu-plugin where?select-1?is a field for currency with?World currency code?values? (USD,?UAH?and so on)

    <?php
    add_filter( 'forminator_set_field_stripe-1', function( $value, $wrapper_id, $name ) {
    	if ( 'currency' === $name ) {
    		$currency_field = 'select-1';
    		$currency       = filter_input( INPUT_POST, $currency_field );
    		if ( $currency ) {
    			$value = $currency;
    		}
    	}
    	return $value;
    }, 10, 3 );

    You can find more information below on how to use mu-plugins.
    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins
    and
    https://www.ads-software.com/support/article/must-use-plugins/

    Kind regards,
    Zafer

    Thread Starter fcis999

    (@fcis999)

    Can you please confirm with me if I need to change anything in the code?

    Like I think I need to make sure the currency dropdown list is named select-1. Anything else?

    Also, after I install it, then this will affect all stripe fields in all my forms on my website? as I only want it on one of the forms.

    • This reply was modified 11 months, 3 weeks ago by fcis999.
    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @fcis999

    I hope you are doing well.

    In case you have multiple select fields you can just update the:

    $currency_field = 'select-1';

    And then add the one that matches your field ID, it is visible when you edit the form: https://monosnap.com/file/VCvF4l5VgJgvOqY6aYiEQu5SYoWb0H

    On the select make sure the value matches the currency code https://monosnap.com/file/R7l8sLU9m4NK4qXHym6tj3neW7Hifw

    Also, after I install it, then this will affect all stripe fields in all my forms on my website? as I only want it on one of the forms.

    This will affect all forms, but I pinged our developers to verify how we can have a limit based on Form ID.

    We will keep you posted.
    Best Regards
    Patrick Freitas

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @fcis999

    An update here

    You can use the following code to limit the form ID:

    <?php 
    
    add_filter( 'forminator_set_field_stripe-1', function( $value, $wrapper_id, $name ) {
    	if ( 'currency' === $name ) {
    		$currency_field = 'select-1';
            $form_id        = filter_input( INPUT_POST, 'form_id' );
            if ( $form_id == 6 ) { // Please change the form ID.
                $currency = filter_input( INPUT_POST, $currency_field );
                if ( $currency ) {
                    $value = $currency;
                }
            }
    	}
    	return $value;
    }, 10, 3 );

    Replace the 6 with your form ID, found in the form shortcode or when editing the form at the page URL.

    Best Regards
    Patrick Freitas

    Plugin Support Zafer – WPMU DEV Support

    (@wpmudevsupport15)

    Hi @fcis999,

    We haven’t heard from you in a while, we will go ahead and mark this thread as resolved. If you have any additional questions or require further help, please let us know!

    Kind regards,
    Zafer

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Change Stripe currency depending on a field’ is closed to new replies.