Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Last active October 5, 2020 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pebblo/f75ec7286e0f1be7619a8581fce36d98 to your computer and use it in GitHub Desktop.
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.
<?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
);
<?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