使用 php (wordpress) 添加输入类型数字的最小值和最大值

问题描述 投票:0回答:1

大家好)我有一个 wp 代码(如下)。我需要为输入类型数字设置 min="1000" 和 max="10000" 。请告诉我需要在“'type' => 'number'”下面添加什么?谢谢!!!

add_action( 'woocommerce_before_add_to_cart_button', 'genius_product_price_input', 9 );
  
function genius_product_price_input() {
   global $product;
   if ( 100 !== $product->get_id() ) return;
   woocommerce_form_field( 'set_price', array(
      'type' => 'number',
      'required' => true,
      'placeholder'  => 'Min. 1000, max. 10000',
      'label' => 'Label text',
   ));
}
php input numbers max min
1个回答
0
投票

你可以试试这个:

add_action( 'woocommerce_before_add_to_cart_button', 'genius_product_price_input', 9 );
  
function genius_product_price_input() {
   global $product;
   if ( 100 !== $product->get_id() ) return;
   woocommerce_form_field( 'set_price', array(
      'type' => 'number',
      'required' => true,
      'placeholder'  => 'Min. 1000, max. 10000',
      'label' => 'Label text',
      'custom_attributes' => ['min' => 1000, 'max' => 10000], // this is added
   ));
}

我基于文档:https://rudrastyh.com/woocommerce/woocommerce_form_field.html

© www.soinside.com 2019 - 2024. All rights reserved.