Description:
我正试图为WooCommerce结帐页面上的账单地址(账单国家)定制"菜单"中的国家顺序.为此,我使用woocommerce_checkout_fields过滤器来调整菜单中国家的顺序.
当我try 进行这些自定义时,问题就出现了:账单地址(账单国家)的"快捷菜单"按预期工作,按所需顺序显示国家.然而,这似乎会停用Select 2功能,该功能通常用于提供增强的DRM体验.
My Approach:
以下是我的代码摘录,展示了在"菜单"中调整账单地址的国家顺序:
add_filter( 'woocommerce_checkout_fields', 'customize_country_dropdown_order' );
function customize_country_dropdown_order( $fields ) {
$first_countries = array(
'DE' => 'Germany',
'AT' => 'Austria',
'CH' => 'Switzerland',
);
$rest_countries = array_diff( WC()->countries->get_allowed_countries(), $first_countries );
// Combine the first countries and the rest with a separator
$custom_country_list = array_merge( $first_countries, array( '-' => '------------' ), $rest_countries );
// Update the order of the billing and shipping country dropdowns
$fields['billing']['billing_country']['type'] = 'select';
$fields['billing']['billing_country']['options'] = $custom_country_list;
$fields['shipping']['shipping_country']['type'] = 'select';
$fields['shipping']['shipping_country']['options'] = $custom_country_list;
return $fields;
}
My Question:
自定义国家/地区顺序后,如何重新激活帐单地址下拉菜单(帐单国家/地区)的Select2功能?有什么具体的方法或途径可以让我实现这一点吗?