此代码可以正常工作,但不能将自定义字段放在我想要的位置。在add_action中,我想使用woocommerce_review_order_after_order_total作为location属性将其放置在页面上。我从视觉指南https://businessbloomer.com/woocommerce-visual-hook-guide-checkout-page/中获得了钩子名称,但是这个钩子(在下面的代码中的注释中看到了,这破坏了我的代码,并给我以下php错误。
Fatal error: Uncaught Error: Call to a member function get_value() on string in /Users/anderskitson/Local Sites/river-cafe/app/public/wp-content/themes/salient-child/functions.php on line 96
希望有人能帮助我。谢谢
/**
* Add custom field to the checkout page
*/
add_action('woocommerce_after_order_notes','custom_checkout_field');
/* add_action('woocommerce_review_order_after_order_total','custom_checkout_field');*/
/* ^ This is the code that is breaking */
function custom_checkout_field($checkout)
{
echo '<div id="custom_checkout_field"><h2>' . __('New Heading') . '</h2>';
woocommerce_form_field(
'custom_field_name',array(
'type' => 'text','class' => array(
'my-field-class form-row-wide'
),'label' => __('Custom Additional Field'),'placeholder' => __('New Custom Field'),),$checkout->get_value('custom_field_name')
);
echo '</div>';
}