我在 wordpress 中使用 php 函式將自定義選擇欄位添加到我的 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 ));
uj5u.com熱心網友回復:
將disabled屬性傳遞給第一個選項就可以了。您可以檢查 woocommerce_form_field() 函式機制以檢查它支持傳遞禁用屬性的方式。
你甚至可以通過 jquery 來做到這一點。通過您的自定義類 my-field-class
$(".my-field-class select option:first").attr("disabled", "true");
uj5u.com熱心網友回復:
您可以使用這樣的占位符變數:
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 ));
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/484602.html
標籤:php WordPress 选择 woocommerce 钩woocommerce
上一篇:在woocommerce上購買后,哪個是掛鉤操作的最佳方式?
下一篇:每X段后插入廣告PHP
