答案是:
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
<div id="product_attributes" class="panel wc-metaboxes-wrapper hidden">
<div class="toolbar toolbar-top">
<span class="expand-close">
<a href="#" class="expand_all"><?php esc_html_e( \'Expand\', \'woocommerce\' ); ?></a> / <a href="#" class="close_all"><?php esc_html_e( \'Close\', \'woocommerce\' ); ?></a>
</span>
<select name="attribute_taxonomy" class="attribute_taxonomy js-ao-select-options">
<option value=""><?php esc_html_e( \'Custom product attribute\', \'woocommerce\' ); ?></option>
<?php
global $wc_product_attributes;
$attribute_taxonomies = wc_get_attribute_taxonomies();
if ( ! empty( $attribute_taxonomies ) ) {
foreach ( $attribute_taxonomies as $tax ) {
$attribute_taxonomy_name = wc_attribute_taxonomy_name( $tax->attribute_name );
$label = $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name;
echo \'<option value="\' . esc_attr( $attribute_taxonomy_name ) . \'">\' . esc_html( $label ) . \'</option>\';
}} ?>
</select>
<script>
jQuery(document).ready(function($){
$(\'.js-ao-select-options\').select2();
});
</script>
<button type="button" class="button add_attribute"><?php esc_html_e( \'Add\', \'woocommerce\' ); ?></button>
从Select区域提交后,width的值变小了,所以我直接修改了CSS(Plugin/woocomece/admin.CSS)以获得更好的效果,但通常不应该像我那样直接修改。该部分负责选择区域的宽度:
.select2-container .select2-selection--single .select2-selection__rendered{line-height:40px;padding-right:24px;width:500px;}