如何在WooCommerce中选择第一个选项选择“无法选择”字段?

发布于 2025-02-03 03:27:03 字数 1023 浏览 5 评论 0原文

我在WordPress中使用PHP功能将自定义Selectfield添加到我的WooCommerce结帐时。 我想使第一个选项(命名为空白)无法选择。我该如何实现?


     woocommerce_form_field( 'cstm_leeftijd'.$i, array(
            'type'          => 'select',
            'class'         => array('my-field-class form-row-first'),
            'label'         => __('Leeftijd bij start Summer Camp'),
            'required' => true,
            'options'       => array(
                 'blank'     => __( 'Selecteer', 'njengah' ),
                 '4'         => __( '4', 'njengah' ),
                 '5'         => __( '5', 'njengah' ),
                 '6'         => __( '6', 'njengah' ),
                 '7'         => __( '7', 'njengah' ),
                 '8'         => __( '8', 'njengah' ),
                 '9'         => __( '9', 'njengah' ),
                 '10'        => __( '10', 'njengah' ),
                 '11'        => __( '11', 'njengah' )
        )), $checkout->get_value( 'cstm_leeftijd'.$i ));

I use a php function in wordpress to add a custom selectfield to my woocommerce checkout.
I want to make the first option (named blank) unselectable. How can i achieve this?


     woocommerce_form_field( 'cstm_leeftijd'.$i, array(
            'type'          => 'select',
            'class'         => array('my-field-class form-row-first'),
            'label'         => __('Leeftijd bij start Summer Camp'),
            'required' => true,
            'options'       => array(
                 'blank'     => __( 'Selecteer', 'njengah' ),
                 '4'         => __( '4', 'njengah' ),
                 '5'         => __( '5', 'njengah' ),
                 '6'         => __( '6', 'njengah' ),
                 '7'         => __( '7', 'njengah' ),
                 '8'         => __( '8', 'njengah' ),
                 '9'         => __( '9', 'njengah' ),
                 '10'        => __( '10', 'njengah' ),
                 '11'        => __( '11', 'njengah' )
        )), $checkout->get_value( 'cstm_leeftijd'.$i ));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

终止放荡 2025-02-10 03:27:03

通过禁用将第一个选项归因于第一个选项。
您可以检查Woocommerce_form_field()函数机制,以检查其支持通过禁用属性的方式。

您甚至可以通过jQuery做到这一点。通过您的自定义课程我的班级

$(".my-field-class select option:first").attr("disabled", "true"); 

Passing disabled attribute to the first option would do the trick.
You can check the woocommerce_form_field() function mechanism to check in which way it supports passing the disabled attribute.

You can even do this by jquery. Through your custom class my-field-class

$(".my-field-class select option:first").attr("disabled", "true"); 
笑咖 2025-02-10 03:27:03

您可以使用类似的放置变量:

 woocommerce_form_field( 'cstm_leeftijd'.$i, array(
            'type'          => 'select',
            'class'         => array('my-field-class form-row-first'),
            'label'         => __('Leeftijd bij start Summer Camp'),
            'required' => true,
            'placeholder'   => __( 'Selecteer', 'njengah' ),
            'options'       => array(
                 '4'         => __( '4', 'njengah' ),
                 '5'         => __( '5', 'njengah' ),
                 '6'         => __( '6', 'njengah' ),
                 '7'         => __( '7', 'njengah' ),
                 '8'         => __( '8', 'njengah' ),
                 '9'         => __( '9', 'njengah' ),
                 '10'        => __( '10', 'njengah' ),
                 '11'        => __( '11', 'njengah' )
        )), $checkout->get_value( 'cstm_leeftijd'.$i ));

you can use a placholder variable like this:

 woocommerce_form_field( 'cstm_leeftijd'.$i, array(
            'type'          => 'select',
            'class'         => array('my-field-class form-row-first'),
            'label'         => __('Leeftijd bij start Summer Camp'),
            'required' => true,
            'placeholder'   => __( 'Selecteer', 'njengah' ),
            'options'       => array(
                 '4'         => __( '4', 'njengah' ),
                 '5'         => __( '5', 'njengah' ),
                 '6'         => __( '6', 'njengah' ),
                 '7'         => __( '7', 'njengah' ),
                 '8'         => __( '8', 'njengah' ),
                 '9'         => __( '9', 'njengah' ),
                 '10'        => __( '10', 'njengah' ),
                 '11'        => __( '11', 'njengah' )
        )), $checkout->get_value( 'cstm_leeftijd'.$i ));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文