Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WooCommerce:将类添加到变体下拉列表_Php_Wordpress_Woocommerce - Fatal编程技术网

Php WooCommerce:将类添加到变体下拉列表

Php WooCommerce:将类添加到变体下拉列表,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我想将class.form控件添加到WooCommerce产品页面的变体下拉列表中 似乎有这样做的选择。我找到了函数wc\u下拉列表\u variation\u属性\u options 该函数有一个class属性: function wc_dropdown_variation_attribute_options( $args = array() ) { $args = wp_parse_args( apply_filters( 'woocommerce_dropdown_variation_a

我想将class
.form控件
添加到WooCommerce产品页面的变体下拉列表中

似乎有这样做的选择。我找到了函数
wc\u下拉列表\u variation\u属性\u options

该函数有一个class属性:

function wc_dropdown_variation_attribute_options( $args = array() ) { 
$args = wp_parse_args( apply_filters( 'woocommerce_dropdown_variation_attribute_options_args', $args ), array( 
    'options' => false,  
    'attribute' => false,  
    'product' => false,  
    'selected' => false,  
    'name' => '',  
    'id' => '',  
    'class' => '',  
    'show_option_none' => __( 'Choose an option', 'woocommerce' ),  
 ) ); 
有没有办法将该类添加到下拉列表中? 我只找到了函数,但没有找到更改class属性的代码/代码段


编辑:我发现了一个自定义下拉列表的代码片段,但我不知道如何仅用于添加类:

答案在
apply\u过滤器('woocommerce\u dropdown\u variation\u attribute\u options\u args',$args)

您基本上需要使用该过滤器来访问正在传递的
$args
。在您的特殊情况下,您可以这样做:

add_filter( 'woocommerce_dropdown_variation_attribute_options_args', static function( $args ) {
    $args['class'] = 'form-control';
    return $args;
}, 2 );

这样做的目的是钩住
woocommerce\u下拉列表\u variation\u attribute\u options\u args
过滤器,并将原始的
$args
传递给一个静态函数。然后基本上设置
$args
数组的
索引的值。然后返回
$args

这是100%准确!在过滤器描述中,存在所有可能的参数,这些参数可以进行更改,而不仅仅是添加一个类。