尝试在woocommerce的结帐页面中的total部分之后放置一个自定义字段

此代码可以正常工作,但不能将自定义字段放在我想要的位置。在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>';
}
ezeke123 回答:尝试在woocommerce的结帐页面中的total部分之后放置一个自定义字段

删除$checkout->get_value('custom_field_name'),使其仅为:

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'),)
);

任何用户值都应自动填写,否则将完全为空。

本文链接:https://www.f2er.com/3156723.html

大家都在问