如何从id php中获取值
如果我将占位符更改为值并将其设置为8或其他不起作用的值,如果它起作用,我需要它从id获取值如何从id php中获取值,php,woocommerce,new-operator,Php,Woocommerce,New Operator,如果我将占位符更改为值并将其设置为8或其他不起作用的值,如果它起作用,我需要它从id获取值 woocommerce_form_field('custom_field1', array( 'id' => 'Hwidth', 'label' => __( 'Width', 'woocommerce' ), 'placeholder' => 'id=Hwidth', 'css' => 'width
woocommerce_form_field('custom_field1', array(
'id' => 'Hwidth',
'label' => __( 'Width', 'woocommerce' ),
'placeholder' => 'id=Hwidth',
'css' => 'width: 20px;',
'type' => 'number',
'required' => true, // Or false
'custom_attributes' => array(
'step' => '0.1',
'min' => '3'
)
)
);
您没有为
woocommerce\u form\u字段
函数赋值。以下是您需要的代码:
$width = get_post_meta( $post_id, '_custom_width', true );
woocommerce_form_field( '_custom_width', // Field ID
array(
'name' => '_custom_width',
'placeholder' => 'Please enter width',
'css' => 'width: 20px;',
'type' => 'number',
'required' => true, // Or false
'custom_attributes' => array(
'step' => '0.1',
'min' => '3'
),
),
$width // Saved Value
);
谢谢:),但是如何从id中获取值。我有一个其他字段,它必须从该字段中获取已保存的数字值。您在哪里添加此字段?在产品页面上?在管理面板中?占位符用于向用户显示替代文本,而不是值。提交后,可通过ID访问该值form@HamidRezaYazdanim我想用PHP和woocommerce做一个纵横比定价组合。我在管理面板中有选项卡,我想当你在那里输入一个值,它会显示在产品页面上。你能发送一个屏幕截图,它们应该显示在哪里吗?这些字段会影响价格吗?