Add woocommerce countries to dropdown

By: Roel Van Aelst | Asked: 01/28/2024
ForumsCategory: General questionsAdd woocommerce countries to dropdown
Roel Van AelstRoel Van Aelst asked 6 months ago
I would like to add a list of countries to a dropdown and it should be the exact same countries as the list of countries available in my Woocommerce installation. 

I have this code but it doesn't work:  // Voeg dropdown-opties toe aan Formidable-formulierveld 177 op basis van WooCommerce-landen
add_filter('frm_setup_field_entry_options', 'add_woocommerce_countries_to_dropdown', 10, 2);
function add_woocommerce_countries_to_dropdown($options, $field) {
// Controleer of het veld het gewenste veld is in het gewenste formulier
if ($field->field_id == 177 && $field->form_id == 23) {
// Haal de lijst met landen op
$countries = wc_get_countries(); // Sorteer de landen alfabetisch op landnaam
asort($countries); // Vul de dropdown-opties
$dropdown_options = array();
foreach ($countries as $code => $name) {
$dropdown_options[$code] = $name;
} // Stel de opties in voor het specifieke veld
$options['options'] = $dropdown_options;
} return $options;
}
1 Answers
Victor Font answered 6 months ago
First of all, I have references to all known Formidable hooks in the Formidable Masterminds Codex. There is no Formidable filter named frm_setup_field_entry_options that I can find. Where did you find that filter referenced?
Victor Font replied 6 months ago

The correct filter should be frm_setup_new_fields_vars: https://formidableforms.com/knowledgebase/frm_setup_new_fields_vars/

There is also no such function as wc_get_countries(). Where did you find that one?

Last, your code produces fatal errors on the Woo function call. You should probably ask a WooCommerce expert what you're doing wrong.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right