0

I have set default country as UK in admin, after the configuration is done, In checkout one empty drop down is showing before the UK country.

so I have used below plugin to remove that empty dropdown.

di.xml

 <type name="Magento\Directory\Model\ResourceModel\Country\Collection">
    <plugin name="country_empty_dropdowns" type="Vendor\Module\Plugin\Country\Collection" sortOrder="1" disabled="false" />
</type>

Collection.php

namespace Vendor\Module\Plugin\Country;


class Collection
{
/**
 * Arguments processing.
 *
 * @param \Magento\Directory\Model\ResourceModel\Country\Collection $subject
 * @param bool $emptyLabel
 *
 * @return bool|array
 */
public function beforeToOptionArray(
     \Magento\Directory\Model\ResourceModel\Country\Collection $subject,
    $emptyLabel = null
) {
    return is_null($emptyLabel) ? [''] : null;
  }
}

Seems code is correct, but still i can see empty dropdown before the default country in checkout as well as in cart page.

Please anyone look into it and update your thoughts. Thanks

0

After plugin is worked for me.

Below is the full code.

class Collection
{
/**
 * Arguments processing.
 *
 * @param \Magento\Directory\Model\ResourceModel\Country\Collection $subject
 * @param bool $emptyLabel
 *
 * @return bool|array
 */
public function afterToOptionArray(
    \Magento\Directory\Model\ResourceModel\Country\Collection $subject,
    $options
) {
    $result = array_filter($options, function ($option) {
        return empty($option['value']) ? false : true;
     });
     return $result;
 }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.