在我的woocommerce产品页面中,我尝试添加一个自定义输入字段,以便客户可以在结帐过程中输入数量字段中的值 .

我在Woocommerce网站上找到了关于钩子/动作http://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/的一些文档 .

我已将下面的代码添加到我的functions.php文件中,至少它应该在产品字段上显示一个输入字段,但它只显示h2值 .

<?php
/**
* Add the field to the product page
*/
add_action( 'woocommerce_before_add_to_cart_button', 'custom_quantity' );

function custom_quantity( $product ) {

echo '<div id="my_custom_checkout_field"><h2>' . __('My Field') . '</h2>';

woocommerce_form_field( 'my_field_name', array(
    'type'          => 'text',
    'class'         => array('my-field-class form-row-wide'),
    'label'         => __('Fill in this field'),
    'placeholder'   => __('Enter something'),
    ), $product->get_value( 'my_field_name' ));

echo '</div>';

}
?>

任何人都可以帮助解决这个问题的原因吗?我的代码中是否有错误 . 我是woocommerce的新手,并试图解决这个问题 .