• 解決済 d-xanthus

    (@d-xanthus)


    お世話になります。
    Contact Form 7のStripeインテグレーションで決済フォームを作成したいのですが、セレクタやラジオボタンの選択肢にあわせて支払価格を変更したいのです。

    価格はカスタムフィールドより取得するので、こちらの方法でなんとかなりそうなのですが、
    https://contactform7.com/2021/10/16/customizing-stripe-payment-parameters/
    セレクタやラジオボタンの選択でのスクリプト(できればjQuery)での変更方法があれば、
    ご教授いただければ助かります。

    何卒よろしくお願いします。

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック投稿者 d-xanthus

    (@d-xanthus)

    自己解決できました。
    フォームにテキストフィールドあるいはhiddenフィールドに、選択肢の結果をjQueryで値を入力後、以下コードにより値を反映させることができました。

    質問内のサイトを参考にカスタマイズしてます。

    例)

    • CF7内に”stripe-amount” フィールドを作成し、セレクタやラジオの選択結果の値をjQueryをつかって入力させる。
    • 同じく[stripe]タグを設置し、functions.phpに以下コードを設置
      ※[stripe]タグのオプションは入力可能です。
    add_filter('wpcf7_stripe_payment_intent_parameters', 
    function( $params ){
    // Get the WPCF7_Submission object
    $submission = WPCF7_Submission::get_instance();

    // Put your currency here in uppercase
    //「通貨」のフィールド値から通貨を取得します(今回不使用)
    $currency = (array) $submission->get_posted_data( 'your-currency' );
    $currency = (string) array_shift( $currency );
    $params['currency'] = strtolower( $currency );

    // get value from input name=stripe-amount
    // "stripe-amount" フィールド値から値を取得します
    $amount = (array) $submission->get_posted_data( 'stripe-amount' );
    $amount = (string) array_shift( $amount );
    $params['amount'] = $amount;

    // Retrieve the buyer's email from the 'your-email' field value
    // "your-email"フィールド値から購入者のメールを取得します(今回不使用)
    $receipt_email = $submission->get_posted_data( 'your-email' );
    if ( is_email( $receipt_email ) ) {
    $params['receipt_email'] = $receipt_email;
    }

    // See https://stripe.com/docs/api/payment_intents/create
    // for the full list of available parameters
    return $params;
    },
    10,1);
1件の返信を表示中 - 1 - 1件目 (全1件中)
  • このトピックに返信するにはログインが必要です。