Con el módulo de integración Stripe de Contact Form 7, me gustaría personalizar la cantidad de la etiqueta del formulario según el valor de la casilla de verificación seleccionada por el usuario.
<input type="checkbox" name="checkboxPrice" value="10€"> <input type="checkbox" name="checkboxPrice" value="30€">[moneda de la franja:cantidad en euros:checkboxPriceValue "Ir a la caja" "Pagar"]
Como se menciona aquí , es posible reemplazar dinámicamente la cantidad de etiqueta de callos según la opción seleccionada por el usuario, pero no puedo hacerlo.
add_filter( 'wpcf7_stripe_payment_intent_parameters', function ( $params ) { // Get the WPCF7_Submission object $submission = WPCF7_Submission::get_instance(); // Retrieve the currency from the 'your-currency' field value $currency = (array) $submission->get_posted_data( 'your-currency' ); $currency = (string) array_shift( $currency ); $params['currency'] = strtolower( $currency ); // Calculate the amount $amount = checkboxPriceValue; $params['amount'] = $amount; $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 );Cualquier ayuda sería apreciada !
¡Ahora obtengo la cantidad correcta según la casilla de verificación seleccionada por el usuario al enviar y se pasa con éxito a Stripe!
Aquí está el shortcode de Stripe que uso:
**[stripe currency:eur amount:1000 "Go to checkout" "Pay !"]**Ahora la casilla de verificación se usa para definir dinámicamente el precio de Stripe, solo dos opciones para mí con este código abreviado:
**[checkbox* checkbox-price class:checkbox-price-unit use_label_element exclusive default:1 "10€" "18€"]** $('input:checkbox[name=checkbox-price]').on('change', function(){ let $checkboxPriceItem = $('input:checkbox[name=checkbox-price]'), $stripeAmount = $('#stripeAmount'); if ( $checkboxPriceItem[0].checked ) { $stripeAmount.val('1000'); } else if ( $checkboxPriceItem[1].checked ) { $stripeAmount.val('1800'); } }); // The stripe field with the price value <input type="hidden" name="stripeAmount" value="1000" id="stripeAmount"> // Customize stripe price add_filter('wpcf7_stripe_payment_intent_parameters', function ( $params ) { // Get the WPCF7_Submission object $submission = WPCF7_Submission::get_instance(); // Retrieve the currency from the 'your-currency' field value //$currency = (array) $submission->get_posted_data( 'your-currency' ); //$currency = (string) array_shift( $currency ); // Put your currency here in uppercase $currency = 'EUR'; $params['currency'] = strtolower( $currency ); // get value from input name=stripeAmount $amount = (array) $submission->get_posted_data( 'stripeAmount' ); $amount = (string) array_shift( $amount ); // Optional, add security so that user can't change this value with JS if ( $amount == 1000 || $amount == 1800) { $params['amount'] = $amount; } else { return false; } // Retrieve the buyer's email from the 'your-email' field value $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 );