Different Stripe price for logged in users

I would like to create a form, with stripe payment, where if users are logged in to a site, they will get different pricing.

  • Dimitris
    • Support Star

    Hello there Paul

    There are some workarounds for this case. You can accomplish that with some custom code. In order to do so, please create a new MU plugin file like /wp-content/mu-plugins/forminator-stripe-logged-in-users.php (just create the /mu-plugin/ folder, if it doesn’t exist already) and insert the exact snippet in it:

    <?php
    add_filter( 'forminator_field_stripe_markup', function( $html, $attr, $field ){

    if ( ! is_user_logged_in() ) {
    return $html;
    }

    $new_price = 18.8;

    $stripe = new Forminator_Gateway_Stripe();
    $forminator_stripe = new Forminator_Stripe();
    $id = Forminator_Stripe::get_property( 'element_id', $field );
    $element_name = $id;
    $field_id = $id . '-field';
    $mode = Forminator_Stripe::get_property( 'mode', $field, 'test' );
    $currency = Forminator_Stripe::get_property( 'currency', $field, $stripe->get_default_currency() );
    $amount_type = Forminator_Stripe::get_property( 'amount_type', $field, 'fixed' );
    $amount = Forminator_Stripe::get_property( 'amount', $field, '0' );
    $amount_variable = Forminator_Stripe::get_property( 'variable', $field, '' );
    $logo = Forminator_Stripe::get_property( 'logo', $field, '' );
    $company_name = Forminator_Stripe::get_property( 'company_name', $field, '' );
    $product_description = Forminator_Stripe::get_property( 'product_description', $field, '' );
    $customer_email = Forminator_Stripe::get_property( 'customer_email', $field, '' );
    $checkout_label = Forminator_Stripe::get_property( 'checkout_label', $field, '' );
    $remember_me = Forminator_Stripe::get_property( 'remember_me', $field, true, 'bool' );
    $collect_address = Forminator_Stripe::get_property( 'collect_address', $field, 'none', 'string' );
    $verify_zip = Forminator_Stripe::get_property( 'verify_zip', $field, false, 'bool' );
    $language = Forminator_Stripe::get_property( 'language', $field, 'en' );
    $stripe_key = ( 'test' == $mode ) ? $stripe->get_test_key() : $stripe->get_live_key();

    $attr = array(
    'type' => 'hidden',
    'name' => $element_name,
    'id' => $field_id,
    'data-is-payment' => 'true',
    'data-payment-type' => $forminator_stripe->type,
    'data-key' => esc_html( $stripe_key ),
    'data-currency' => esc_html( strtolower( $currency ) ),
    'data-amount-type' => esc_html( $amount_type ),
    'data-amount' => $new_price, //( 'fixed' === $amount_type ? esc_html( $amount ) : $amount_variable ),
    'data-label' => esc_html( $checkout_label ),
    'data-allow-remember-me' => esc_html( $remember_me ? 'true' : 'false' ),
    'data-locale' => esc_html( $language ),
    );

    if ( ! empty( $logo ) ) {
    $attr['data-image'] = esc_url( $logo );
    }

    if ( ! empty( $company_name ) ) {
    $attr['data-name'] = esc_html( $company_name );
    }

    if ( ! empty( $company_name ) ) {
    $attr['data-description'] = esc_html( $product_description );
    }

    if ( ! empty( $customer_email ) ) {
    $attr['data-email'] = esc_html( $customer_email );
    }

    if ( 'billing' === $collect_address || 'billing_shipping' === $collect_address ) {
    $attr['data-billing-address'] = 'true';
    }

    if ( 'billing_shipping' === $collect_address ) {
    $attr['data-shipping-address'] = 'true';
    }

    if ( $verify_zip ) {
    $attr['data-zip-code'] = 'true';
    }

    $html = Forminator_Stripe::create_input( $attr );

    return $html;

    }, 20, 3 );

    Keep in mind to replace the value of the $new_price = 18.8; with the value you need for the logged-in users.

    Another workaround would be to create two different forms, one for logged-in and another for not logged-in users, and use a little plugin like this one https://wordpress.org/plugins/user-access-shortcodes/ in order to display the proper form to each user group.

    Warm regards,

    Dimitris

  • Paul
    • WPMU DEV Initiate

    Thank you Dimitri for this nice resolution to this issue. Your comment about restrictive access reminding me that I already have a solution! We use MemberPress, which has the ability to selective display/not display page areas based on whether the user is logged in or not.

    Thank you.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.