Last active
October 5, 2020 19:32
-
-
Save Pebblo/f75ec7286e0f1be7619a8581fce36d98 to your computer and use it in GitHub Desktop.
This function ties the Stripe country dropdown into the 'active' countries set within Event Espresso -> General Settings. By default payment method forms display ALL countries, this forces the Stripe form to only display active countries.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //Please do not include the opening PHP tag if you already have one | |
function ee_stripe_country_dropdown_filter( $options, $form ) { | |
if( $form instanceof EE_Billing_Attendee_Info_Form | |
&& isset( $options[ 'name' ] ) | |
&& $options[ 'name' ] === 'Stripe_Payment_Intent_and_Elements_Form' | |
) { | |
if(isset($options[ 'subsections' ]['country'])) { | |
$options[ 'subsections' ]['country'] = | |
new EE_Country_Select_Input( | |
null, | |
array( | |
EE_Country_Select_Input::OPTION_GET_KEY => EE_Country_Select_Input::OPTION_GET_ACTIVE, | |
'html_label_text' => esc_html__('Country', 'event_espresso'), | |
'required' => true, | |
'html_class' => 'ee-billing-qstn ee-billing-qstn-country', | |
) | |
); | |
} | |
} | |
return $options; | |
} | |
add_filter( | |
'FHEE__EE_Form_Section_Proper___construct__options_array', | |
'ee_stripe_country_dropdown_filter', | |
10, | |
2 | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //Please do not include the opening PHP tag if you already have one | |
function ee_stripe_country_dropdown_filter( $options, $form ) { | |
if( $form instanceof EE_Billing_Attendee_Info_Form | |
&& isset( $options[ 'name' ] ) | |
&& $options[ 'name' ] === 'Stripe_Payment_Intent_and_Elements_Form' | |
) { | |
// Pull the payment methods related to this form and check if the admin name is 'Stripe limited' | |
$payment_method = $form->payment_method(); | |
if($payment_method instanceof EE_Payment_Method) { | |
if(!$payment_method->admin_name() === 'Stripe limited') { | |
return $options; | |
} | |
} | |
// We want to limit this payment methods country selection based on EE settings. | |
if(isset($options[ 'subsections' ]['country'])) { | |
$options[ 'subsections' ]['country'] = | |
new EE_Country_Select_Input( | |
null, | |
array( | |
EE_Country_Select_Input::OPTION_GET_KEY => EE_Country_Select_Input::OPTION_GET_ACTIVE, | |
'html_label_text' => esc_html__('Country', 'event_espresso'), | |
'required' => true, | |
'html_class' => 'ee-billing-qstn ee-billing-qstn-country', | |
) | |
); | |
} | |
} | |
return $options; | |
} | |
add_filter( | |
'FHEE__EE_Form_Section_Proper___construct__options_array', | |
'ee_stripe_country_dropdown_filter', | |
10, | |
2 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment